How to print from GitHub

If I want to print a markdown file from GitHub as it appears on screen, for example: https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md Then how can I accomplish that? What code do I need to change in the resulting github html page (that I save) such that the printout will honor the look & feel of the markdown? So far the only clue I have is this one: https://makandracards.com/makandra/4947-how-to-print-github-wiki-pages But it is more of a utilitarian (non-programmatic) workaround which doesn't really work because the markdown interpreter in use isn't as forgiving as the one running on the GitHub websites so it fumbles.

26.8k 9 9 gold badges 62 62 silver badges 86 86 bronze badges asked Apr 3, 2012 at 17:28 pulkitsinghal pulkitsinghal 4,025 13 13 gold badges 47 47 silver badges 85 85 bronze badges

21 Answers 21

Here is a bookmarklet that works for me:

  1. Copy the contents of the bookmarklet Gist, reproduced below as a backup.
  2. Create a new bookmark in the toolbar of your browser, give it a fitting name.
  3. Put that one line of code in the URL field.

If you now go to a Markdown page on Github and click the bookmark it will reformat the page and change the CSS so that it looks the same as on screen when you print. It will also automaticaly trigger the printing dialog to pop up.

javascript:document.body.appendChild(document.querySelector("#readme"));document.querySelector("header").remove();document.querySelector(".application-main").remove();document.querySelector("footer").remove();window.print(); 
answered Jun 28, 2012 at 8:43 Boris Terzic Boris Terzic 10.9k 8 8 gold badges 46 46 silver badges 60 60 bronze badges

I found this bookmarklet wasn't properly removing the Github header for logged in users, so I updated it at an updated gist here

Commented Jan 4, 2013 at 18:32 broken since new github design Commented Jun 20, 2013 at 9:51

Is there an uncompressed version of this file anywhere in case I want to try out some edits ? This is all compressed / encrypted code in the gist currently.

Commented Oct 1, 2013 at 22:14 Answer has been updated with the latest version from @randomor Commented Jun 13, 2014 at 2:18 Here's one for 2022: gist.github.com/davidcann/2d65fb189cdee31a6dcaa248f46afec3 Commented Jun 10, 2022 at 17:43

Here's a super simple solution: Simply select all the text in the readme that you want to print, then print and choose "Only selected text".

This worked perfectly in Chrome (including images) and required no javascript or external sites or downloading or building software.

answered Aug 30, 2017 at 7:26 2,263 3 3 gold badges 22 22 silver badges 26 26 bronze badges

Nice! The option in Chrome is now called More settings -- Selection only . It supports the formatting and doesn't require additional software or downloading the markdown file.

Commented Nov 4, 2017 at 4:23

When printing from Firefox, select the content you want to print, access the "Print" option from the "File" menu (or press ctrl + p ), then select the "Selection" option.

Commented Oct 14, 2019 at 22:26 This is the way. As of Chrome 107, just select the text, right click -> Print. Commented Nov 9, 2022 at 16:46

Another option is pandoc. After installing (it supports Windows, Linux and Mac OS), the command would be along the lines of pandoc file.md -f markdown --smart -s -o file.pdf

Then print the resulting PDF file.

There is also this online converter, which produced the nicest output for me: http://www.markdowntopdf.com/

Pandoc has an online demo as well.

Update 2020: on macOS Catalina this command worked for me:

brew install pandoc brew install --cask basictex pandoc README.md -f markdown+smart -s -o out.pdf --pdf-engine=/Library/TeX/texbin/pdflatex --pdf-engine=xelatex 
15k 8 8 gold badges 86 86 silver badges 82 82 bronze badges answered May 12, 2016 at 2:05 354 3 3 silver badges 9 9 bronze badges Found this tool very effective markdowntopdf.com Commented Oct 31, 2020 at 22:01 How to get original markdown from random public issue? e.g. github.com/ethereum/EIPs/issues/650 Commented Mar 29, 2022 at 7:44

If you are a Mac-User, another great possibility is to use the "Reader"-Functionality in the Safari web browser.

Just open the markdown-File and click the "Reader"-Button in the top right-corner.

Then just print the page with the command "CMD + P".

Works like a charm.

answered Feb 17, 2014 at 19:13 798 6 6 silver badges 16 16 bronze badges This no longer seems to work on the latest iOS/Safari :( Commented Mar 20, 2019 at 15:59

Works well on macOS 10.14 Mojave, although I had filename positioned below my H1 (largest header) on the first line of a .md (markdown) file weirdly after printing a hardcopy to paper.

Commented Mar 29, 2021 at 21:17

I made a Chrome extension that does just this: GitHub Markdown Printer. It's a one-click solution for printing markdown files exactly how they appear on GitHub.

Steps:

  1. Install the Chrome extension
  2. Go to any page on GitHub/GitHub Enterprise with a markdown preview
  3. Click the GMP icon to open the print dialog and either print or save as PDF

Check out the repo for more info.

answered Sep 9, 2018 at 20:10 175 3 3 silver badges 4 4 bronze badges The extension reads and writes to all pages you visit. Not sure how secure it is Commented Nov 8, 2019 at 15:38

@VikramKhemlani That's a valid concern, but I assure you I'm not doing anything malicious. The read permission is required to see if 1) you are on github and 2) if there is a valid markdown preview. The write permission is required to add a custom stylesheet to remove the extra elements when printing. The project is open-source and you can find the source code here: github.com/jerry1100/github-markdown-printer/tree/master/src. If you're still doubtful, you can open the network tab in your chrome devtools and find that I'm not sending any data anywhere.

Commented Nov 8, 2019 at 19:19

@JerryWu There is a way to manually setup the extension to work only on gist.github.com and github.com pages when managing extensions in the browser and I'm pretty sure there is also a way to set defaults for those settings in your extension's code, right away. Anyways, kudos, your extension is better than marking and copying the page, because it will provide better styles, so much text can be printed on each page. I like this extension. Only problem I see is that it reserves pages for the comments on gist.github.com, so I have to specify the page start/end to not print a lot of empty pages.

Commented Mar 25, 2021 at 23:48

@MartinBraun thanks for the feedback. When I was developing this, I was working at IBM and needed to match github.ibm.com. Since github.*.com isn't a valid match pattern, I went with my current approach. If you know of a less-invasive way, let me know and I'll try it out. Also, I fixed the issue with comments on gists, look out for v0.6 :)

Commented Mar 27, 2021 at 7:35

Good news - as of v0.8, this extension no longer requires any permissions or site access, thanks to the new manifest v3 APIs.