252

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?

3

15 Answers 15

288

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

Visual Studio Code Markdown PDF

Sign up to request clarification or add additional context in comments.

9 Comments

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.
Note: For me the second solution only worked after restarting VSCode
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.
The answer rocks! it works well with images and code snippets unlike the other alternatives.
Yzane Markdown PDF extension still working on December 2024.
|
82

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

8 Comments

using the online service, I keep getting Error generating PDF.
The online service seems broken now.
@ÁrpádMagosányi well, I use it on Ubuntu. be specific what doesn't work.
Works on Ubuntu 19.04 command line. A few event related warnings, but produces a correct pdf.
I tested it, tables don't seem to have separating lines in the output PDF
|
45

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.

5 Comments

pandoc -t beamer -o output.pdf yourInput.mkd produces only one pdf page. Extra contents are cut.
@alhelal Same issue here. Any hints?
@rkioji Try the tip from the other answer, add *** where you want to break a page.
To install the dependencies on Fedora: sudo dnf install -y pandoc texlive-beamer texlive-ec
Last link johnmacfarlane.net is dead. The domain probably does not exist anymore.
25

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.

3 Comments

pandoc errored out on me, because of "too nested" lists (was trying to print an outliner export), dillinger worked, thanks!
dillinger.io renders HTML tags as text in tables, eg. b<sub>7</sub> | b<sub>6</sub> | etc... does not display subscript in the HTML preview, but funnily enough the PDF output is correct, so thanks from me also!
I tried couple of Online Markdown to PDF converters, dillinger.io was best. It preservs the links and table.
14

I found that many markdown-to-pdf converters produce files that I don't find exactly neat-looking. However there is a solution to this.

If you're using IntelliJ, you can use a plugin called "Markdown". The export function uses pandoc as an engine so you probably will need to install that along with pdf-latex. https://pandoc.org/installing.html

In IntelliJ, under Tools > Markdown Converter > Export Markdown File To...

And there you go, a clean looking document. Additional styling can be added via a .css stylesheet.

Comments

8

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.

Comments

8

Previously I had used the npm markdown-pdf answer. However, on a fresh install of Ubuntu 19.04 (Disco Dingo) I had issues getting it to install correctly.

Instead I started using the Visual Studio Code package: "Markdown PDF"

Details:
Name: Markdown PDF
Id: yzane.markdown-pdf
Description: Convert Markdown to PDF
Version: 1.2.0
Publisher: yzane
Visual Studio Marketplace link: https://marketplace.visualstudio.com/items?itemName=yzane.markdown-pdf

It has worked consistently well. If you've had issues getting other answers to work, I would recommend trying this.

1 Comment

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.
7

With python script:

pip install markdown-pdf

from markdown_pdf import Section, MarkdownPdf
    
pdf = MarkdownPdf()
# each section starts from new page in pdf file
pdf.add_section(Section("###Hello\n* abc\n* def\n"))  # page 1
pdf.add_section(Section("###Bye\n* ghi\n* jkl\n"))  # page 2
pdf.save("out.pdf")

2 Comments

Too bad that I can define the page margin size. It does not support hr element.
unfortunately it doesn't even make the font bigger for ###
5

Using Okular

  1. Make sure your file has the ".md" extension.
  2. Open in Okular
  3. File -> Export As -> PDF -> Select save location and save.

Using discount

To go the Markdown -> HTML -> PDF path, you can use the discount package directly (Okular uses it)

  1. Say your file is named "filename.md". Use markdown filename.md > outfile.html to get the html into an html file "outfile.html".
  2. Use your preferred method of converting HTML to PDF.
  • discount also has other binaries: theme and makepage - which you can check out for their specific features.

1 Comment

Simple and working
5

Using pandoc's docker image is one option.

docker run --rm \
       --volume "$(pwd):/data" \
       --user $(id -u):$(id -g) \
       pandoc/latex README.md -o outfile.epub

https://hub.docker.com/r/pandoc/latex

Comments

3

I've managed to get a stable Markdown -> HTML > PDF pipeline working with the MarkReport project.

It is a bit more than what Pandoc will do though, since it is based on WeasyPrint and is therefore aimed for clean report publishing, with cover, headers, sections, ... It also enriches the HTML with syntax highlighting and LaTeX equations.

1 Comment

Minor note: pandoc can export via WeasyPrint, too. (Useful, e.g., when targeting HTML from a document containing citations).
3

I suggest using mdtopdf. It supports syntax highlighting, pagination and dark, light and custom themes.

Install md2pdf by obtaining the release for your arch and OS (deb and RPM packages are also available) or, if you have go installed, invoke:

$ go install github.com/mandolyte/mdtopdf/v2/cmd/md2pdf@latest

md2pdf is also available via Homebrew:

$ brew install md2pdf

If you require syntax highlighting, download the gohighlight lexers

md2pdf supports all major markdown features and accepts local files, remote HTTP(s) URL and STDIN inputs. The below command will convert a markdown file to a PDF with a dark theme, syntax highlighting (you'll need to provide the language hint, of course), page/slide separation and a footer:

md2pdf -i https://github.com/jessp01/crash-course-in/raw/main/courses/apt_dpkg_deb/apt_dpkg_deb.md \
    -o apt_dpkg_deb.pdf \
    -s ~/.config/zaje/syntax_files \
    --theme dark \
    --new-page-on-hr \
    --with-footer \
    --author "Jesse Portnoy <[email protected]>" \
    --title "A crash course on handling deb packages"

Comments

2

Simple way with iOS:

Use Shortcuts app (by Apple)

Make Rich Text From Markdown: Clipboard

^

Make PDF from Rich Text From Markdown

^

Show [PDF] in Quick Look

Just copy text and run the shortcut. Press share in Quick Look (bottom left) to store or send it. I use this to quickly convert Joplin notes to pdf.

Comments

2

Use the python md2pdf library with weasyprint.

pip install md2pdf weasyprint

Then convert your file

md2pdf inputfile.md outputfile.pdf

Want more control over formatting? Grab some markdown css from here: https://github.com/sindresorhus/github-markdown-css

Then use:

md2pdf --css markdown.css inputfile.md outputfile.pdf

2 Comments

md2pdf and weasyprint are very slow when generating to PDF, using a small and simple CSS file.
@Oo'-: I haven't experienced slowness. How large is your markdown input file?
1

This is somewhat a hack, but I found that this method was the easiest for rendering math equations (easier than pandoc-based solutions)

  1. Install Markdown Preview Enhanced
  2. Open Preview
  3. "Open in Browser"
  4. Print

3 Comments

The "Open in Browser" step opens my md file inside to VSCode; please let me know how to open it externally on a browser to print.
Hmm, what happens if you do this? Right Click > Export > HTML > HTML (offline)
I don't have this "Export" option, but no worries, I solved it using the "Markdown PDF" extension, thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.