DEV Community

Franklin Strube
Franklin Strube

Posted on

How to convert Markdown to PDF

There are a million and one document formats out there that all seem to do one thing or another. However, I've found that simplicity is key. You want something that is simple to read under-the-hood, but predictable when presented on screen.

Avoid classic word-processors like MS Word

Document formats like MS Word are risky because, while universal, they are subject to things like text re-flow, especially when opened in different environments (either the fonts are missing or don't work, or your word processor renders the content differently compared to mine).

PDFs are known for being consistent

PDF is a bullet-proof format when it comes to display, and when created properly, it embeds fonts so that it will always be rendered perfectly on any machine. However, PDF documents under-the-hood aren't quite that readable by human eyes.

Markdown is a simple text-based format

Enter Markdown. Markdown is a format that is human-readable. Paragraphs are simply lines of text. Headings begin with a single #-sign or more. Bold text is surrounded by stars like **this**. It's just easy on the eyes.

Markdown to PDF is a powerful workflow

Typically, Markdown is converted to HTML in order to be formatted for the web. This is great, but what if you're not serving the Markdown via a browser? If you're a student, you may be required to turn in a PDF of your assignment. What if you want to generate a PDF so you can publish a book? By writing your documents in Markdown and converting them to PDF, you get the ease of writing text plus the ubiquity of displaying a PDF. It's a great workflow for publishing printable media.

How do you convert Markdown to PDF?

There are a handful of excellent command-line tools, and Pandoc comes to mind. It is not just a one-trick pony, too. With Pandoc you can convert between many different formats.

Another option is to go with a purpose-built tool, like SlickPDF. I built slickpdf.com for the very purpose of going from Markdown to PDF. Give it a try!. It uses marked.js under the hood, and presents a live preview rendered on a Letter-size (8.5 in. x 11 in.) page.

Image description

Conclusion

So the next time you need to publish a PDF either for school, or for work, or just for fun, consider writing it in Markdown. You'll get the ease of "just typing" and a beautiful end product.

Top comments (0)