Web Developer & Consultant

Writing in Markdown & Converting Markdown to PDF

24 December 2012

I've discovered markdown a while back, when I've started using Symphony-CMS, I found markdown was clean simple to understand and allows me to do what I wanted without too much hassle, write. Indeed such was its simplicity, that I changed by Blog to allow me to write using markdown. No more formatting issues there; however I then required something more production of reports, thus I wanted my Markdown to be converted into PDF.

My First line of thought, and early use was to produce this onilne, Feed the Markdown to Symphony as usual and produce my standard HTML, then I would add on a pdf-generating extension which takes care of generating the pdf document for myself. I've tried this and it worked out nicely, the url2pdf extension provided a very good service as long as what I needed to do was going to be online and in single pages.

However I eventually wanted to start writing my own dissertation, previously I had been annoyed with using a Word Editor & inDesign, whilst they do their job its an overkill design wise and the documents just get too big to process. So I opted to start writing in Markdown, tracking all the changes using github, that way I could see and follow up my writing from anywhere. The only question-mark I had was how to eventually generate my Dissertation PDF without having to copy the finalized content over to something else.

That led me to start searching for ways of converting multi-page html documents to PDF, and then markdown to Latex since I knew latex was quite popular for document writing, except it was a new syntax for me so I'd prefer to use markdown. Then along that search I cam across Pandoc.

Markdown to PDF with Pandoc

First of all I have to say that Pandoc has been a life-saver, it allows content to be changed from/to various formats. Markdown, Latex and PDF are just 3 of them, it also has stuff like word processor and open office support.

Conversion from Markdown to PDF is fairly easy, pandoc comes up with a standard latex-template which you can modify, its great if you write a lot of reports and research papers which have to be submitted in various formats as you would just have to replace the template and your markdown content is straight away transformed into the pdf document with the right styling.

All you would need to do to convert your Markdown to PDF is the following:

  • Install pandoc (you can use your package manager on linux)
  • Make sure that you have latex2pdf and bibliography packages if required installed (some packages of pandoc don't have these as required)
  • just run the pandoc command. pandoc -o output.pdf
  • Add optionals such as
    • --toc for a Table of Contents
    • --bibliography mybibliography.bib for a Bibliography
    • --csl bibliographytemplate.csl for a particular Bibliography style
    • --template template.tex to use your own particular template
  • Then just wait a few seconds and you have your finalized PDF

Written by Jonathan Mifsud

Jonathan Mifsud is a web developer by day and an SEO enthusiast by night. He provides freelance web development and consultancy services and is available for hire. You can get in touch with him on twitter and Google+


Leave a Comment
Paul Cobbaut

Too bad pandoc doesn't generate an index in the pdf :( Do you know of other tools to get a pdf from markdown ?


03 Jul 2013 @2:29pm


LaTeX is a good option if you are writing a self-contained document such as a dissertation.


22 Mar 2013 @5:47pm


Pandoc actually uses LaTeX on the way to making a PDF (thus the dependency on latex2pdf). I've found it's not as expressive as LaTeX, but much simpler for most writing.


14 May 2013 @11:52pm

Post a new Comment

Please write your name.
Please enter your comment
Please enter your email address.