⇦ Back

Tested on Windows 7 and Ubuntu 20.04 & 24.04

In order to convert Markdown to PDF from within Sublime Text:

  1. Install Pandoc - a document conversion program - then,
  2. Create a Pandoc Build System in Sublime Text

This will allow you to build a .pdf file from an .md file that is open in Sublime Text.

1 Install Pandoc

On Windows and macOS, go to the installation guide.

On Ubuntu, Pandoc can be installed from the package manager:

$ sudo apt-get install pandoc

Check that it has worked with:

$ pandoc --version

2 Create a Pandoc Build System in Sublime Text

Build Systems tell Sublime Text what code to run when building a program or document and are stored in files with the .sublime-build extension. To create a new one, navigate to Tools > Build System > New Build System... and, in the untitled.sublime-build file that appears, replace everything with

{
    "shell_cmd": "pandoc -o \"$file.pdf\" \"$file\" && open \"$file.pdf\"",
    "selector": "text.html.markdown",
}

Save the Build System into the default folder that is suggested by Sublime Text when you select “Save”. Give it a meaningful name such as Markdown to PDF.sublime-build when you do so.

Note that this Build System will use LaTeX to create the PDF and so you will need to have that installed. To instead use HTML as an intermediate format (convert Markdown to HTML to PDF) and avoid using LaTeX you can add the -t html flag:

{
    "shell_cmd": "pandoc -o \"$file.pdf\" -t html \"$file\" && open \"$file.pdf\"",
    "selector": "text.html.markdown",
}

Note that this will require a tool called “wkhtmltopdf” which can be downloaded from here.

3 Usage

With a Markdown file (one with the .md extension) open and active in Sublime Text, navigate to Tools > Build With... (shortcut: Shift+Ctrl+B) and select “Markdown to PDF” (or whatever it was you called your .sublime-build file). This should create the PDF file and open it.

Note:
From now on, Sublime Text will associate Markdown files with this Build System and automatically run it when Tools > Build (shortcut: Ctrl+B) is selected while a Markdown file is open and active. Two ways to change this behaviour and run a different Build System (eg the “Markdown” Build System from the MarkdownPreview package which converts .md files to HTML) are:

  • Re-running Tools > Build With... (shortcut: Shift+Ctrl+B). Whichever Build System you choose will become the one that is associated with the file type of the active file.
  • Navigating to Tools > Build System and manually selecting a different option. The first option - “Automatic” - will use the Build System currently associated with the file type of the active file.

In most cases, the two Build Systems “Markdown to PDF” (the topic of this page) and “Markdown” (the topic of the Using Markdown page) will provide all the functionality needed for building Markdown files. Just be aware that you may need to switch from one to the other depending on whether you want to build to PDF or to HTML.

⇦ Back