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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

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.