md2pdf
md2pdf is a Visual Studio Code extension that exports Markdown documents to PDF using a local Chrome, Edge, or Chromium installation.
Features
- Export Markdown to PDF from the Command Palette (
md2pdf: Export Markdown to PDF)
- Export Markdown to PDF from the Explorer and editor context menus
- Front matter variables for header and footer templates
- Default header and footer layouts with left, center, and right sections
- GitHub-style Markdown rendering with syntax highlighted code blocks
- Local PDF generation with no remote service dependency
Requirements
md2pdf uses puppeteer-core, so a local Chrome, Edge, or Chromium executable must be available.
If your browser is installed in a non-standard location, set md2pdf.browserExecutablePath in VS Code settings.
Install
From a local VSIX
- Build and package the extension.
- In VS Code or VS Code Insiders, open the Extensions view.
- Select Install from VSIX... from the
... menu.
- Choose the generated
.vsix file.
From source for development
- Clone the repository.
- Run
npm install in the project root.
- Press
F5 in VS Code or VS Code Insiders to launch an Extension Development Host.
Usage
- Open a Markdown document.
- Run md2pdf: Export Markdown to PDF from the Command Palette, or right-click the file/editor and choose the export command.
- Pick the destination PDF file.
Front matter variables
Front matter values are exposed to header and footer templates. Built-in variables include:
{{title}}
{{fileName}}
{{fileStem}}
{{filePath}}
{{generatedAt}}
{{pageNumber}}
{{totalPages}}
Example:
---
title: Sprint Notes
author: Ada Lovelace
project: md2pdf
md2pdf:
header:
left: "{{project}}"
center: "{{title}}"
right: "Page {{pageNumber}} / {{totalPages}}"
footer:
left: "{{author}}"
center: "internal"
right: "{{generatedAt}}"
---
Configuration
Default header and footer sections are configurable in VS Code settings:
md2pdf.header.left
md2pdf.header.center
md2pdf.header.right
md2pdf.footer.left
md2pdf.footer.center
md2pdf.footer.right
md2pdf.page.format
md2pdf.page.margin.top
md2pdf.page.margin.right
md2pdf.page.margin.bottom
md2pdf.page.margin.left
md2pdf.browserExecutablePath
Development
See docs/README.md for developer setup, build, test, package, and publish instructions.
License
MIT
MIT