180

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?

Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
Akshar Raaj
  • 14,231
  • 7
  • 51
  • 45
  • 1
    try using gimli ruby gem. its quite easy, for reference see http://blog.kushdilip.com/2014/02/convert-emberjs-online-guide-using.html – kushdilip Feb 19 '14 at 19:37
  • 2
    For future readers, they may want to check out https://github.com/alanshaw/markdown-pdf – iled Apr 16 '16 at 12:51

9 Answers9

209

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

Community
  • 1
  • 1
yEmreAk.com
  • 3,278
  • 2
  • 18
  • 37
  • 3
    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? – domsson Jan 07 '20 at 14:31
  • 1
    Unfortunately, I have no idea :/ – yEmreAk.com Jan 09 '20 at 07:29
  • 1
    @domsson I had the same problem. Installing `texlive-latex-extra` solved it. – Gerriet Mar 05 '20 at 13:49
  • 36
    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](https://stackoverflow.com/posts/57834015/revisions). This should be a sign that overuse of emoji is not welcome. **Please don't replace them.** – ChrisGPT was on strike Apr 28 '20 at 18:24
  • This answer also fixed an issue I was having on my side: `! LaTeX Error: File \`booktabs.sty' not found.` – Seth Falco Nov 03 '20 at 12:48
  • 7
    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. – lanoxx Nov 30 '20 at 16:04
  • 1
    Note: For me the second solution only worked after restarting VSCode – Matt Apr 27 '21 at 09:02
  • 1
    _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. – deeenes May 03 '21 at 20:10
  • 2
    The answer rocks! it works well with images and code snippets unlike the other alternatives. – NearHuscarl Jul 30 '21 at 07:50
  • 4
    "Emojis are better in Windows than Linux (I don't know why)" This is a font issue, not an OS issue – Lorraine May 24 '22 at 15:10
70

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
oori
  • 5,533
  • 1
  • 30
  • 37
42

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107
15

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mori
  • 973
  • 10
  • 11
  • 1
    `pandoc` errored out on me, because of "too nested" lists (was trying to print an outliner export), dillinger worked, thanks! – Tomáš M. Jan 12 '22 at 07:01
7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tpdsantos
  • 423
  • 5
  • 6
5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John Forbes
  • 1,248
  • 14
  • 19
  • 1
    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. – Rasjid Wilcox Oct 17 '19 at 03:20
4

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.

Romaingin
  • 41
  • 1
  • 1
    Minor note: pandoc can export via WeasyPrint, too. (Useful, e.g., when targeting HTML from a document containing citations). – tarleb Mar 03 '19 at 07:36
3

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.

Nan0fire
  • 31
  • 3
1

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.

SandsByte
  • 11
  • 1