Categories
Linux

convert Markdown files to PDF in Ubuntu

I love it writing short and medium notes in Markdown. For printing or sharing with others I often use the PDF format.

To convert Markdown files into other formats, like PDF, HTML, etc., you can use pandoc.

Using Latex

Installation in Ubuntu

For installation just install package pandoc. For PDF conversion you need some latex packages too.

sudo apt install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra pandoc

Conversion to PDF

To convert your markdown file test.md into test.pdf you need to run the following command:

pandoc -t latex -o test.pdf test.md

Sometimes I had some problems with “complex” markdown files. Especially if i use nested ordered / unordered lists. One solution is to use the html5 engine of pandoc.

Using HTML

Currently this is my preferred way for conversation, because it is more stable. You can also setup some styling with a simple CSS file.

Installation in Ubuntu

For installation just install package pandoc and the rendered wkhtmltopdf.

sudo apt install wkhtmltopdf pandoc

Conversion to PDF

Now it is like the usage of latex, but with a small different parameter (example is with paper size A4):

pandoc -t html5 -V papersize=a4 -o test.pdf test.md

Further variables can be read in the manual of pandoc.