How to print from GitHub

GithubMarkdownPretty Print

Github Problem Overview


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.

Github Solutions


Solution 1 - Github

Here is a bookmarklet that works perfectly 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. Now just print the page.

Bookmarklet contents:

javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc=a.createElement(%22script%22);c.type=%22text/javascript%22;c.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+g+%22/jquery.min.js%22;c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd==%22loaded%22%7C%7Cd==%22complete%22))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.3.2%22,function($,L)%7B$('%23header,%20.pagehead,%20.breadcrumb,%20.commit,%20.meta,%20%23footer,%20%23footer-push,%20.wiki-actions,%20%23last-edit,%20.actions,%20.header,.site-footer,.repository-sidebar,.file-navigation,.gh-header-meta,.gh-header-actions,#wiki-rightbar,#wiki-footer,.commit-tease').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D);%20$('link').removeAttr('media');%7D); var removeMe = document.getElementsByClassName("file-header")[0]; removeMe.parentNode.removeChild(removeMe);

Solution 2 - Github

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.

This is what I tested on: https://github.com/kroitor/gjk.c/blob/master/README.md

Solution 3 - Github

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 cask install basictex
pandoc README.md -f markdown+smart -s -o out.pdf --pdf-engine=/Library/TeX/texbin/pdflatex --pdf-engine=xelatex

Solution 4 - Github

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.

Solution 5 - Github

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.

Solution 6 - Github

Found an awesome tool that achieves the printing results that I asked for: http://plessl.github.com/wkpdf/

Here's a quote from its website: "If you want to render a website with all the graphical icing to exactly match the view in a browser, you can explicitly force the use of the CSS screen stylesheet and enable the printing of background images as in the following example ..."

So I ran:

wkpdf --source https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md
      --stylesheet-media screen
      --print-background yes
      --output printIt.pdf

and it was magical!

Solution 7 - Github

I'm using the github-wiki-print browser extension to print GitHub wiki pages.

I think you might edit its manifest.json file to print any markdown file on GitHub repos.

Solution 8 - Github

clone the repo

gem install bluecloth
  • render the markdown files into html
  • open file on your filesystem in your browser
  • print from your browser

http://deveiate.org/projects/BlueCloth

you can find examples of the api here: http://deveiate.org/projects/BlueCloth/browser/spec/bluecloth_spec.rb

Solution 9 - Github

I recommend taking a picture with http://awesomescreenshot.com/, then cropping the image and printing (I just did this and it worked for me :).

Solution 10 - Github

Super easy way that require nothing more than Chrome:

You can spoof the user-agent, telling you are a mobile device, to get a nice printable version.

The way I do it - there are plenty of ways - I use Chrome the Chrome devTools "Emulation" feature to emulate an Android device, e.g. a Samsung Note 3, then in the screen sub-section I remove "Emulate screen", to get full resolution, then I print.

Solution 11 - Github

Simple Hack:

I've been opening the markdown file in something like Marked or the online tool Dillinger and then print from there. Some of these tools allow you to set the formatting to Github or other styles.

A better way:

Since I first wrote the above answer I found a better way:

I've discovered a better way than what I said earlier.

  1. Git clone your wiki to a local directory

  2. Use gitbook & Calibre's ebook-convert to generate the PDF as per the instructions in https://github.com/GitbookIO/gitbook

    • On the Mac, you have to symlink the ebook-convert from within the /Application/calibre.app directory to someplace suitable before running the gitbook pdf command, with a command like:

    ln -s /Applications/calibre.app/Contents/console.app/Contents/MacOS/ebook-convert /usr/local/bin

Solution 12 - Github

Try grip.

pip install grip
grip markdown.md

Then it is hosted on a local port. You can then print or save to PDF through your native OS print dialog from your favourite browser.

See here.

Solution 13 - Github

Another way is just download the markdown from GitHub or Bit Bucket and open it with eclipse. You will get the preview tab in the editor pane. From file menu select print. Simple way, however I am taking liberty to assume you already have eclipse installed usually most of developers have it.

BR

Solution 14 - Github

I use this page http://www.markdownprint.com, really simple to use and produces markdown using the github style (which looks really good). Highly recommend!

Solution 15 - Github

Simply convert MD file into PDF

You may download your .md file and upload it here to convert it into a pdf file. Which you can easily print.

Solution 16 - Github

http://github.com/github/markup

You don't mention a language preference, but this is the Ruby library GitHub itself uses to render the markup files. It has the advantage of supporting the various markups GitHub supports (textile, rdoc etc). Rendering .markdown files has a dependency on the redcarpet markdown parser:

http://github.com/tanoku/redcarpet

Solution 17 - Github

If you have an Instapaper account, navigate to the README.md file, save the link to Instapaper, then open the "text" option in Instapaper on that link. Most of the "clutter" is removed and the page prints well.

Solution 18 - Github

I used MarkdownPad and printed the HTML to a PDF writer. If you have Pro you can export to PDF directly.

Solution 19 - Github

Works for Chromium browsers and "current" GitHub html page structure

  1. Create a bookmark
  2. In the Address field enter :

javascript:var content = document.querySelector('.repository-content'); 
var toc = document.querySelector('#wiki-rightbar');
toc.innerHTML = '';
var wb = document.querySelector('.has-rightbar .wiki-body');
wb.style.marginRight = '0px';
var body = document.querySelector('body'); 
body.innerHTML = ''; 
body.appendChild(content);
window.print();

Selects the Wiki text, removes and formats the table of content, replaces the body content and calls the printer.

Solution 20 - Github

In Firefox it is super easy.

  1. Select the portion to be printed, by simply dragging mouse from begin to end of the area to be printed.
  2. Go to the print menu File -> Print (Ctrl-P will also work)
  3. Click 'Selection' instead of Original under the 'Format' option of the print menu
  4. Hit Print. The preview should also show what is going to be printed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpulkitsinghalView Question on Stackoverflow
Solution 1 - GithubBoris TerzicView Answer on Stackoverflow
Solution 2 - GithubSrekelView Answer on Stackoverflow
Solution 3 - GithubkitsuneView Answer on Stackoverflow
Solution 4 - GithubpmuensView Answer on Stackoverflow
Solution 5 - GithubJerry WuView Answer on Stackoverflow
Solution 6 - GithubpulkitsinghalView Answer on Stackoverflow
Solution 7 - GithubGiovanni CappellottoView Answer on Stackoverflow
Solution 8 - GithubJed SchneiderView Answer on Stackoverflow
Solution 9 - GithubDTrejoView Answer on Stackoverflow
Solution 10 - GithubJulien BérubéView Answer on Stackoverflow
Solution 11 - GithubRobert J BergerView Answer on Stackoverflow
Solution 12 - GithubozOliView Answer on Stackoverflow
Solution 13 - GithubJeetView Answer on Stackoverflow
Solution 14 - GithubJohan OView Answer on Stackoverflow
Solution 15 - GithubNishant ShahView Answer on Stackoverflow
Solution 16 - GithubPero P.View Answer on Stackoverflow
Solution 17 - GithubRalphView Answer on Stackoverflow
Solution 18 - GithubTobiasView Answer on Stackoverflow
Solution 19 - GithubcrocteamggView Answer on Stackoverflow
Solution 20 - GithubA. K.View Answer on Stackoverflow