DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

How to Convert Markdown to PDF/docx

There are a lof options out there but I would suggest to use pandoc to convert your markdown files to PDF, docx etc..

From Ubuntu pandoc manpage:

Pandoc is a Haskell library for converting from one markup format to another, and a
command-line tool that uses this library. It can read Markdown, CommonMark, PHP Markdown
Extra, GitHub-Flavored Markdown, MultiMarkdown, and (subsets of) Textile,
reStructuredText, HTML, LaTeX, MediaWiki markup, TWiki markup, Haddock markup, OPML, Emacs
Org mode, DocBook, txt2tags, EPUB, ODT and Word docx; and it can write plain text,
Markdown, CommonMark, PHP Markdown Extra, GitHub-Flavored Markdown, MultiMarkdown,
reStructuredText, XHTML, HTML5, LaTeX (including beamer slide shows), ConTeXt, RTF, OPML,
DocBook, OpenDocument, ODT, Word docx, GNU Texinfo, MediaWiki markup, DokuWiki markup,
ZimWiki markup, Haddock markup, EPUB (v2 or v3), FictionBook2, Textile, groff man pages,
Emacs Org mode, AsciiDoc, InDesign ICML, TEI Simple, and Slidy, Slideous, DZSlides,
reveal.js or S5 HTML slide shows. It can also produce PDF output on systems where LaTeX,
ConTeXt, or wkhtmltopdf is installed.

To convert just write:

$ pandoc README.md -o README.pdf
Enter fullscreen mode Exit fullscreen mode

where -o is "output".

By default, pandoc produces a document fragment, not a standalone document with a proper header and footer. To produce a standalone document, use the -s or --standalone flag:

$ pandoc -s -o output.html input.txt
Enter fullscreen mode Exit fullscreen mode

For more information go and visit pandoc official page.

All done!

Top comments (0)