MD2PDF Converter is a Visual Studio Code extension that exports Markdown documents to PDF using a local Chrome, Edge, or Chromium installation.
Buy me a coffee
If you'd like to thank me, you can buy me a coffee. Coffee is never too much :)
https://www.buymeacoffee.com/websvc
- Export Markdown to PDF beside the source Markdown file without prompting for a save path
- Export Markdown to PDF as ... from the Command Palette and Markdown 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
- Inline HTML line break snippets such as
<br>in Markdown content - Inline HTML page break snippets such as
<pagebreak />in Markdown content - Layered custom stylesheets from built-in styles, project CSS, and front matter CSS paths
- Local PDF generation with no remote service dependency
MD2PDF Converter 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-converter.browserExecutablePath in VS Code settings.
- 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
.vsixfile.
- Clone the repository.
- Run
npm installin the project root. - Press
F5in VS Code or VS Code Insiders to launch an Extension Development Host.
- Open a Markdown document.
- Run MD2PDF Converter: Export Markdown to PDF to save
your-file.pdfnext toyour-file.md. - Use MD2PDF Converter: Export Markdown to PDF as ... when you want to choose a different file name or location.
To force a line break in exported output, use an inline HTML break snippet in your Markdown:
First line<br>
Second lineTo force the next content onto a new PDF page, insert this HTML snippet in your Markdown:
Section one
<pagebreak />
Section twoUse the snippet on its own line (block context). <div class="page-break"></div> is also supported.
Every exported document starts with the built-in MD2PDF Converter stylesheet.
You can then add two optional override layers:
- A project stylesheet named
md2pdf-converter.cssormd2pdf.css. The nearest matching file above the Markdown document is loaded automatically. - A front matter stylesheet path under
md2pdf-converter.css.
Effective precedence is:
- Built-in MD2PDF Converter styles
- Project stylesheet
- Front matter stylesheet
Example:
---
title: Styled Notes
md2pdf-converter:
css: styles/pdf.css
---The front matter path may be absolute, relative to the Markdown file, or project-relative if it can be found by walking up parent directories.
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 Converter
md2pdf-converter:
header:
left: "{{project}}"
center: "{{title}}"
right: "Page {{pageNumber}} / {{totalPages}}"
footer:
left: "{{author}}"
center: "internal"
right: "{{generatedAt}}"
---Default header and footer sections are configurable in VS Code settings:
md2pdf-converter.header.leftmd2pdf-converter.header.centermd2pdf-converter.header.rightmd2pdf-converter.footer.leftmd2pdf-converter.footer.centermd2pdf-converter.footer.rightmd2pdf-converter.page.formatmd2pdf-converter.page.margin.topmd2pdf-converter.page.margin.rightmd2pdf-converter.page.margin.bottommd2pdf-converter.page.margin.leftmd2pdf-converter.browserExecutablePath
See docs/README.md for developer setup, build, test, package, and publish instructions.