How to Convert Markdown (.MD) Files to PDF on Linux

Markdown (.MD) files are a favorite among developers, writers, and content creators due to their simplicity and flexibility, but what happens when you need to share your beautifully formatted Markdown file with someone who prefers a more universally accepted format, like PDF?

On Linux, you have several tools and methods to achieve this seamlessly and this guide will walk you through the process of converting .MD files to .PDF, ensuring your documents look professional and polished.

Method 1: Using Pandoc – A Document Converter

Pandoc is a powerful command-line tool for converting files between different formats and most Linux distributions have Pandoc available in their repositories.

sudo apt install pandoc         [On Debian, Ubuntu and Mint]
sudo dnf install pandoc         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo apk add pandoc             [On Alpine Linux]
sudo pacman -S pandoc           [On Arch Linux]
sudo zypper install pandoc      [On OpenSUSE]    
sudo pkg install pandoc         [On FreeBSD]

Once installed, converting a Markdown file to PDF is as simple as running a single command:

pandoc input.md -o output.pdf
Convert MD File to PDF
Convert MD File to PDF

Method 2: Markdown Preview in VS Code

Visual Studio Code (VS Code) is a popular text editor that supports Markdown preview and export.

First, install VS Code from your distribution’s repository or download it from the official site and then install the Markdown PDF extension.

Install Markdown PDF Extension
Install Markdown PDF Extension

Next, open your .md file in VS Code and press F1 or Ctrl+Shift+P and type export and select markdown-pdf: Export (pdf).

VS Code Convert MD to PDF File
VS Code Convert MD to PDF File

Method 3: Using Grip Tool

Grip is a Python-based tool that renders Markdown in your web browser, which is especially useful for previewing Markdown as it would appear on GitHub.

pip install grip

Once installed, you can run the following command to render your Markdown file:

grip sample.md

Grip starts a local server, open the provided URL in your browser, and then use the browser’s print functionality to save the rendered file as a PDF.

Method 4: Using Calibre eBook Manager

Calibre is a feature-rich eBook management tool that supports various formats, including Markdown.

sudo apt install calibre         [On Debian, Ubuntu and Mint]
sudo dnf install calibre         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo apk add calibre             [On Alpine Linux]
sudo pacman -S calibre           [On Arch Linux]
sudo zypper install calibre      [On OpenSUSE]    
sudo pkg install calibre         [On FreeBSD]

Once installed, open Calibre and add your .md file and then right-click on the file and select Convert Books > Convert Individually.

Choose PDF as the output format and click OK.

Convert .md to PDF in Linux
Convert .md to PDF in Linux
Conclusion

Converting Markdown to PDF on Linux is straightforward and offers multiple methods tailored to your workflow. Whether you prefer the command-line power of Pandoc, the simplicity of VS Code, or the visual rendering of Grip, Linux has you covered.

With these tools, you can create professional, shareable PDFs from your Markdown files in no time.

Two small things before you go

If something didn’t work on your setup, leave a comment and tell me which distro and version you’re on. I read every one, and most of these articles got better because a reader pointed out what was missing.

And if it did work, share it. TecMint has stayed free for 14 years because people pass these articles around, and that traffic is what pays for writing the next one.

Leave a comment
Get two free Linux courses

Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.

Pro TecMint
Get lifetime access for $99

If you want to go beyond the free tutorials, Pro gives you 18 courses, 5 ebooks, and every future course I add. One payment, lifetime access, no renewals.

Ravi Saive
Ravi Saive
Administrator
About the author

I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.