How to convert a Markdown file to PDF

174,782

Solution 1

Via the terminal (tested in 2020)

Download dependencies

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

Try to use

pandoc MANUAL.txt -o example13.pdf
pandoc MANUAL.md -o example13.pdf

Via a Visual Studio Code extension (tested in 2020)

  • Download the Yzane Markdown PDF extension
  • Right click inside a Markdown file (md)
  • The content below will appear
  • Select the Markdown PDF: Export (pdf) option

Note: Emojis are better in Windows than Linux (I don't know why)

Visual Studio Code Markdown PDF

Solution 2

2016 update:

NPM module: https://github.com/alanshaw/markdown-pdf

Has a command line interface: https://github.com/alanshaw/markdown-pdf#usage

npm install -g markdown-pdf
markdown-pdf <markdown-file-path>

Or, an online service: http://markdown2pdf.com

Solution 3

As SpeakerDeck only accepts PDF files, the easiest option is to use the Latex Beamer backend for pandoc:

pandoc -t beamer -o output.pdf yourInput.mkd

Note that you should have LaTeX Beamer installed for that.

In Ubuntu, you can do sudo apt-get install texlive-latex-recommended to install it. If you use Windows, you may try this answer.

You may also want to try the HTML/CSS output from Slidy:

pandoc --self-contained -t slidy -o output-slidy.html yourInput.mkd

It has a decent printing output, as you can check out trying to print the original.

Read more about slideshows with pandoc here.

Solution 4

Easy online solution: dillinger.io.

Just paste your Markdown content into the editor on the left and see the (html) preview on the right. Then click Export as on the top and chose pdf.

It's based on the open source dillinger editor.

Solution 5

Adding to elias' answer, if you want to separate text in slides, just put *** between the text you want to separate. For your example to be in several pages, write it like this:

### Hello
- abc
- def

***

### Bye
- ghi
- jkl

And then use elias' answer, pandoc -t beamer -o output.pdf yourInput.md.

I have Ubuntu 18.10 (Cosmic Cuttlefish) and installed the full package from texlive. It works for me.

Share:
174,782

Related videos on Youtube

Akshar Raaj
Author by

Akshar Raaj

I am a software developer with 6+ years of professional software development experience. I have worked with several funded and successful companies. I have worked with small teams as well as large organizations. Get in touch to talk about it in detail. I have served organizations in various capacities which include Backend developer, Full stack developer, Individual Contributor and Technical Architect. I have taken projects from conception phase to production. I know what it takes to architect a scalable and maintainable product. I love working on challengine problems and finding innovative and simple solutions for them. I frequently blog about my learnings. You can read them at https://www.agiliq.com/authors/#Akshar. My posts have been read over a million times :) I strongly believe that if correct processes and tools are in place, then any company can reach it's goals irrespective of the team size location and timezone of its employees.

Updated on February 05, 2022

Comments

  • Akshar Raaj
    Akshar Raaj about 2 years

    I have a Markdown file that I wish to convert to PDF so that I can upload it on Speakerdeck. I am using Pandoc to convert from markdown to PDF.

    My problem is I can't specify what content should go on what page of the PDF, because Markdown doesn't provide any feature like that.

    E.g., Markdown:

    ###Hello
    * abc
    * def
    
    ###Bye
    * ghi
    * jkl
    

    Now I want Hello to be one slide and Bye to be on another slide on Speakerdeck. So, I will need them to be on different pages in the PDF that I generate using Pandoc.

    But both Hello and Bye gets on the same page in the PDF.

    How can I accomplish this?

  • Shadi
    Shadi over 6 years
    using the online service, I keep getting Error generating PDF.
  • alhelal
    alhelal over 6 years
    pandoc -t beamer -o output.pdf yourInput.mkd produces only one pdf page. Extra contents are cut.
  • juminet
    juminet about 6 years
    The online service seems broken now.
  • oori
    oori about 6 years
    @ÁrpádMagosányi well, I use it on Ubuntu. be specific what doesn't work.
  • tarleb
    tarleb about 5 years
    Minor note: pandoc can export via WeasyPrint, too. (Useful, e.g., when targeting HTML from a document containing citations).
  • rph
    rph almost 5 years
    @alhelal Same issue here. Any hints?
  • Alfian Nahar
    Alfian Nahar almost 5 years
    @rkioji Try the tip from the other answer, add *** where you want to break a page.
  • rickfoosusa
    rickfoosusa almost 5 years
    Works on Ubuntu 19.04 command line. A few event related warnings, but produces a correct pdf.
  • Elouan Keryell-Even
    Elouan Keryell-Even over 4 years
    I tested it, tables don't seem to have separating lines in the output PDF
  • Rasjid Wilcox
    Rasjid Wilcox over 4 years
    I've just done this on both Windows and Linux. Installation was a breeze in both cases, and worked well without any configuration or setup.
  • domsson
    domsson over 4 years
    On Debian, after installing those dependencies and running the command above (using a .md instead of a .txt file, however), I get an error: File 'letltxmacro.sty' not found. - despite that file apparently being part of texlive-latex-base. Would you have any idea on why that happens?
  • Yedhrab
    Yedhrab over 4 years
    Unfortunately, I have no idea :/
  • Gerriet
    Gerriet about 4 years
    @domsson I had the same problem. Installing texlive-latex-extra solved it.
  • Chris
    Chris almost 4 years
    We've been over this: Excessive emoji are unnecessary and distracting. Most of the ones that were in this answer are poorly-chosen and don't add any value. You will note that an 800k+ reputation moderator removed emoji from one of your posts a couple of weeks ago. This should be a sign that overuse of emoji is not welcome. Please don't replace them.
  • Daniel Lombraña González
    Daniel Lombraña González almost 4 years
    If you don't want to install the tool, you can do it with npx: npx markdown-pdf <mardkown-file-path>
  • Timo
    Timo almost 4 years
    apt-get install latex-beamer does not work because not available
  • Alfian Nahar
    Alfian Nahar almost 4 years
    @Timo thanks, i've just checked and as of today, beamer is now included in texlive-latex-recommended, so that's the package name to use. I'll update the answer.
  • Bryce Guinta
    Bryce Guinta over 3 years
    To install the dependencies on Fedora: sudo dnf install -y pandoc texlive-beamer texlive-ec
  • Seth Falco
    Seth Falco over 3 years
    This answer also fixed an issue I was having on my side: ! LaTeX Error: File `booktabs.sty' not found.
  • lanoxx
    lanoxx over 3 years
    In a debian:10 docker image, this tries to install 1GB of dependencies, all that just to convert a few kilobytes of Markdown into PDF. I wonder if there is a solution that involves a bit less overhead.
  • Matt
    Matt about 3 years
    Note: For me the second solution only worked after restarting VSCode
  • deeenes
    deeenes almost 3 years
    The Linux OS doesn't support emojis well (Windows is better) -- I doubt it's the duty of operating systems to support emojis. I guess it's about applications.
  • NearHuscarl
    NearHuscarl over 2 years
    The answer rocks! it works well with images and code snippets unlike the other alternatives.
  • Tomáš Pospíšek
    Tomáš Pospíšek over 2 years
    unfortunately markdown-pdf seems to be dead and doesn't work either on current Ubuntu nor on current Debian systems as of 2021-09-01, see here
  • Tomáš M.
    Tomáš M. over 2 years
    pandoc errored out on me, because of "too nested" lists (was trying to print an outliner export), dillinger worked, thanks!
  • stafusa
    stafusa about 2 years
    Now the website is back online, but the output is not perfect: in my test the list markers were not in the same line as the items and "italic" between quotes wasn't recognized.
  • OmarL
    OmarL almost 2 years
    "Emojis are better in Windows than Linux (I don't know why)" This is a font issue, not an OS issue