How to convert a Markdown file to PDF
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)
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.
Related videos on Youtube
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, 2022Comments
-
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 andBye
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
andBye
gets on the same page in the PDF.How can I accomplish this?
-
kushdilip about 10 yearstry using gimli ruby gem. its quite easy, for reference see blog.kushdilip.com/2014/02/…
-
iled about 8 yearsFor future readers, they may want to check out github.com/alanshaw/markdown-pdf
-
-
Shadi over 6 yearsusing the online service, I keep getting
Error generating PDF.
-
alhelal over 6 years
pandoc -t beamer -o output.pdf yourInput.mkd
produces only one pdf page. Extra contents are cut. -
juminet about 6 yearsThe online service seems broken now.
-
oori about 6 years@ÁrpádMagosányi well, I use it on Ubuntu. be specific what doesn't work.
-
tarleb about 5 yearsMinor note: pandoc can export via WeasyPrint, too. (Useful, e.g., when targeting HTML from a document containing citations).
-
rph almost 5 years@alhelal Same issue here. Any hints?
-
Alfian Nahar almost 5 years@rkioji Try the tip from the other answer, add
***
where you want to break a page. -
rickfoosusa almost 5 yearsWorks on Ubuntu 19.04 command line. A few event related warnings, but produces a correct pdf.
-
Elouan Keryell-Even over 4 yearsI tested it, tables don't seem to have separating lines in the output PDF
-
Rasjid Wilcox over 4 yearsI'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 over 4 yearsOn 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 oftexlive-latex-base
. Would you have any idea on why that happens? -
Yedhrab over 4 yearsUnfortunately, I have no idea :/
-
Gerriet about 4 years@domsson I had the same problem. Installing
texlive-latex-extra
solved it. -
Chris almost 4 yearsWe'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 almost 4 yearsIf you don't want to install the tool, you can do it with npx: npx markdown-pdf <mardkown-file-path>
-
Timo almost 4 years
apt-get install latex-beamer
does not work because not available -
Alfian Nahar almost 4 years@Timo thanks, i've just checked and as of today,
beamer
is now included intexlive-latex-recommended
, so that's the package name to use. I'll update the answer. -
Bryce Guinta over 3 yearsTo install the dependencies on Fedora:
sudo dnf install -y pandoc texlive-beamer texlive-ec
-
Seth Falco over 3 yearsThis answer also fixed an issue I was having on my side:
! LaTeX Error: File `booktabs.sty' not found.
-
lanoxx over 3 yearsIn 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 about 3 yearsNote: For me the second solution only worked after restarting VSCode
-
deeenes almost 3 yearsThe 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 over 2 yearsThe answer rocks! it works well with images and code snippets unlike the other alternatives.
-
Tomáš Pospíšek over 2 yearsunfortunately 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. over 2 years
pandoc
errored out on me, because of "too nested" lists (was trying to print an outliner export), dillinger worked, thanks! -
stafusa about 2 yearsNow 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 almost 2 years"Emojis are better in Windows than Linux (I don't know why)" This is a font issue, not an OS issue