Skip to content

Instantly share code, notes, and snippets.

@M1ke
Created July 15, 2021 11:39
Show Gist options
  • Save M1ke/8098e28860f6130dd239eff018c0dfea to your computer and use it in GitHub Desktop.
Save M1ke/8098e28860f6130dd239eff018c0dfea to your computer and use it in GitHub Desktop.
Simple command line tool using python's grip library and wkhtmltopdf to generate a PDF file from a Markdown file. Basically starts a server, captures it as a PDF and then kills the server (that's the complex bit!)
#!/bin/bash
# Install grip $ pip install grip
# Install wkhtmltopdf $ sudo apt-get install wkhtmltopdf
md=$1
pdf=$md.pdf
port=$(( ( RANDOM % 6000 ) + 5000 ))
echo $port
grip $md localhost:$port &
sleep 10
wkhtmltopdf http://localhost:$port $pdf
kill $(ps -eo pid,command | grep "grip" | grep -v grep | awk '{print $1}')
@M1ke
Copy link
Author

M1ke commented Jul 15, 2021

Run this with

bash markdown-to-github-pdf.sh my-file.md

It will output my-file.md.pdf for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment