Skip to content

Instantly share code, notes, and snippets.

@justincbagley
Last active December 26, 2025 14:12
Show Gist options
  • Select an option

  • Save justincbagley/ec0a6334cc86e854715e459349ab1446 to your computer and use it in GitHub Desktop.

Select an option

Save justincbagley/ec0a6334cc86e854715e459349ab1446 to your computer and use it in GitHub Desktop.
How To Convert Markdown to PDF

How to convert markdown to PDF:

This post reviews several methods for converting a Markdown (.md) formatted file to PDF, from UNIX or Linux machines.

Using Pandoc:

$ pandoc How_I_got_svg-resizer_working_on_Mac_OSX.md -s -o test1.pdf

Other methods:

GRIP

http://superuser.com/questions/689056/how-can-i-convert-github-flavored-markdown-to-a-pdf I've had success using grip to display markdown in Chrome and then use Chrome's "Save as PDF" option in the Print dialog.

pip install grip  
grip your_markdown.md

grip will render the markdown on localhost:5000 ... - just edit away and refresh the browser. Print when ready.

This gave a more reliable representation than pandoc and was lighter weight than installing LaTeX (required by pandoc for pdf generation).

The print is not command line in this answer, but still found this easier/more reliable (looked 100% like Github for a long document including relatively linked images and code highlighting).

Node.js

http://superuser.com/questions/689056/how-can-i-convert-github-flavored-markdown-to-a-pdf You can also use Node.js based markdown-pdf

npm install -g markdown-pdf
markdown-pdf /path/to/markdown

NOTES:

The GRIP results look just like GitHub README pages. The Pandoc result looks like (is) LaTex format. And the Node.js result is the most original looking, but slightly harder to read than GRIP output PDF. Overall, I prefer GRIP output.

@sskras
Copy link

sskras commented Sep 1, 2023

@tektutor: By "it" do you mean pandoc, grip or markdown-pdf (Node.js) tool?

@elvinagam
Copy link

Works perfectly. Thanks.

Install VS Code Extension Markdown Pdf

Now Open Command Pallete Ctrl+Shift+P

Then choose Markdown PDF: Export(pdf) and then pdf will be generated in the corresponding directory.

@niepiekm
Copy link

Please try this one using VS Code, it worked for me.

* Install VS Code Extension `Markdown Pdf`

* Now Open Command Pallete `Ctrl+Shift+P`

* Then choose `Markdown PDF: Export(pdf)` and then pdf will be generated in the corresponding directory.

Great tip! Thanks.

@PitGartmann
Copy link

PitGartmann commented Mar 20, 2024

Did you have any issues with the VsCode Extension Markdown PDF when using a GitHub remote Repository? I was using GitLab before that which worked perfectly, but now that I changed to GitHub it doesnt seem to work anymore. Im not getting specific errors, but only the message that the file destination cannot be found.

Managed to fix the Problem myself. It was due to one of my files not having the .md ending.

@hpssjellis
Copy link

Please try this one using VS Code, it worked for me.

  • Install VS Code Extension Markdown Pdf
  • Now Open Command Pallete Ctrl+Shift+P
  • Then choose Markdown PDF: Export(pdf) and then pdf will be generated in the corresponding directory.

Thank you @ajaykumar2017

@hannes-angst
Copy link

Markdown PDF failed (on a Mac) to render my SVG images correctly. The SVG have a white background defined, but Markdown PDF render them in black.

@EdwardMatthews
Copy link

Check out https://pdftomarkdown.pro/ to get clean Markdown from a PDF.

@tsilvs
Copy link

tsilvs commented Oct 7, 2025

grip failed to render admonitions and tables, generally failed with most of styling.

@18272837023
Copy link

18272837023 commented Dec 19, 2025

你好@wisnubaldas可能已经找到了,不过你可以用Pandoc。我还试验了一些免费的在线转换器,效果也相当不错,例如https://pdf2md.morethan.io。另外,还有一个Python程序,叫[PDF to Markdown](https://pypi.org/project/pdf-to-markdown/),你可以用它进行安装`pip`。

It's December 2025 now, and I never imagined technology would advance so rapidly. Deepseek's OCR technology can now directly extract PDF files into Markdown format.

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