Pandoc Markdown to PDF

Learn to easily convert Pandoc markdown to PDF. Install Pandoc, convert markdown to PDF, and securely share your PDF live on the web.
Pandoc Markdown to PDF

Despite the existence of powerful search engines, it’s often hard to find the information you need to solve a particular problem. One problem I ran into was an article assignment to show how to convert Pandoc markdown to PDF. There are a number of ways to convert markdown to PDF. Why use Pandoc?

Pandoc is a command-line format-to-format converter. And it converts a ton of formats both back and forth. For instance, just some of the formats it handles are HTML, EPUB, MS Word, Rich Text Format, Open Office Format, Jupyter notebooks, Wiki formats, MS PowerPoint, XML, and JSON. Wow!

As a developer, you may wish to automate batch conversions or just do a one-off or many conversion types. Pandoc makes this process simple—if you have the right information.

I’ll use the example of markdown to PDF to show how it’s done. Then I’ll show you how to share your PDF with the free Tiiny.host PDF file hosting service.

Installing Pandoc

Pandoc.org provides an auto-detect download button for the Pandoc installer for your operating system. This is the simplest way to install it.

Pandoc is available in a number of flavors. Choose your platform below for full installation instructions.

Pandoc PDF Conversion Dependencies

Pandoc relies on the LaTeX typesetting tool for its PDF conversions.

LaTeX (pronounced “Lay-tek”) is primarily used in medium or large-scale publishing, especially technical and scientific documents. The installer is a large download. It doesn’t make a lot of sense to install it if you’re only doing a couple of PDFs. But for consistent use or automation, it is an elegant and industry-standard tool.

There are many distributions of LaTeX. Pandoc recommends the MikTeX distribution.

MikTeX, like Pandoc, is available for a variety of platforms, each with their own automatic download buttons:

And that’s all there is to it! You can now use Pandoc and MikTeX (LaTeX) to convert your markdown files into PDFs easily.

Using Pandoc to convert markdown text to PDF

Now we get to see how powerful this Pandoc/LaTeX combination is.

For this example, prepare by making a test markdown file (or choose one of your own), then convert that file to a PDF.

Navigate to the directory containing your md file or simply use your current directory.

Enter the following on the command line:

Then add some text to the file:

Now, to convert your markdown file to a PDF, enter the following on the command line:

With any luck, your conversion is complete!

Use the open command from your command line to open the PDF. Or, open it from within a PDF reader.

Troubleshooting

If you receive the following error, then close and reopen the terminal window.

If the error persists, check your installation to see that pdflatex is installed, and its directory is in your $PATH variable. Use the “which command” command to find the path to pdflatex. If the result is empty, you must locate the directory where pdflatex is installed and append it to your $PATH variable. Your platform will determine how you do this.

Pandoc formatting options

You may now wish to try out a markdown file with full formatting.

Here’s an example to try:

Visit https://pandoc.org/demo/MANUAL.txt.

Select all, copy, and paste this text into your test.md file.

If it still exists, delete the previous test.pdf file using the rm command. (Just in case!)

  1. create the fully formatted PDF file:

Note the optional parameter –pdf-engine=pdflatex.

This is just one of a large number of formatting and usage parameters. For a good introduction to all the various options, just read the PDF you made with this part of the tutorial. It is the Pandoc user manual, now in PDF format, thanks to your diligence. Good job!

Pandoc Extras

Many Pandoc and LaTeX utilities are available to help make your life easier.

Visit thePandoc Extras Wiki page on GitHub to see a reasonably complete list of GUIs, editors, CLI wrappers, website tools, and other useful stuff.

Next Steps

Once your PDF is finalized, and you are happy with it, it’s time to share it.

If you wish to share it on the web, there is no easier way to do it than by uploading it for free to Tiiny.host.

Three steps are all it takes to quickly and securely host your PDF and share it with your audience.

  1. Type in a link-name which will be the first part of the URL you will share.
  2. Drag & drop—or upload—your PDF file in the central field, and choose the PDF option.
  3. Click the big, blue “Upload” button, and you’re done.

That’s it!

Tiiny.host also supports password protection and analytics with a paid plan. Host static websites, individual files such as images, or HTML files. There are even more features available on Tiiny.host, and more are coming.

Visit Tiiny.host for more information, or contact support directly through chat or email. Customer service on Tiiny.host is awesome!