Markdown PDF

This extension converts Markdown files to pdf, html, png or jpeg files.

Japanese README

Table of Contents

Specification Changes

Features

Supports the following features

Sample files

markdown-it-container

INPUT

::: warning *here be dragons* :::

OUTPUT

<div class="warning"> <p><em>here be dragons</em></p> </div>

markdown-it-plantuml

INPUT

@startuml Bob -[#red]> Alice : hello Alice -[#0000FF]->Bob : ok @enduml

OUTPUT

PlantUML

markdown-it-include

Include markdown fragment files: :[alternate-text](relative-path-to-file.md).

├── [plugins] │ └── README.md ├── CHANGELOG.md └── README.md

INPUT

README Content :[Plugins](./plugins/README.md) :[Changelog](CHANGELOG.md)

OUTPUT

Content of README.md Content of plugins/README.md Content of CHANGELOG.md

mermaid

INPUT

```mermaid
stateDiagram
    [*] --> First
    state First {
        [*] --> second
        second --> [*]
    }
```

OUTPUT

mermaid

Install

Chromium download starts automatically when Markdown PDF is installed and Markdown file is first opened with Visual Studio Code.

However, it is time-consuming depending on the environment because of its large size (~ 170Mb Mac, ~ 282Mb Linux, ~ 280Mb Win).

During downloading, the message Installing Chromium is displayed in the status bar.

If you are behind a proxy, set the http.proxy option to settings.json and restart Visual Studio Code.

If the download is not successful or you want to avoid downloading every time you upgrade Markdown PDF, please specify the installed Chrome or 'Chromium' with markdown-pdf.executablePath option.

Usage

Command Palette

  1. Open the Markdown file
  2. Press F1 or Ctrl+Shift+P
  3. Type export and select below
    • markdown-pdf: Export (settings.json)
    • markdown-pdf: Export (pdf)
    • markdown-pdf: Export (html)
    • markdown-pdf: Export (png)
    • markdown-pdf: Export (jpeg)
    • markdown-pdf: Export (all: pdf, html, png, jpeg)

usage1

  1. Open the Markdown file
  2. Right click and select below
    • markdown-pdf: Export (settings.json)
    • markdown-pdf: Export (pdf)
    • markdown-pdf: Export (html)
    • markdown-pdf: Export (png)
    • markdown-pdf: Export (jpeg)
    • markdown-pdf: Export (all: pdf, html, png, jpeg)

usage2

Auto convert

  1. Add "markdown-pdf.convertOnSave": true option to settings.json
  2. Restart Visual Studio Code
  3. Open the Markdown file
  4. Auto convert on save

Extension Settings

Visual Studio Code User and Workspace Settings

  1. Select File > Preferences > UserSettings or Workspace Settings
  2. Find markdown-pdf settings in the Default Settings
  3. Copy markdown-pdf.* settings
  4. Paste to the settings.json, and change the value

demo

Options

List

Category Option name Configuration scope
Save options markdown-pdf.type
markdown-pdf.convertOnSave
markdown-pdf.convertOnSaveExclude
markdown-pdf.outputDirectory
markdown-pdf.outputDirectoryRelativePathFile
Styles options markdown-pdf.styles
markdown-pdf.stylesRelativePathFile
markdown-pdf.includeDefaultStyles
Syntax highlight options markdown-pdf.highlight
markdown-pdf.highlightStyle
Markdown options markdown-pdf.breaks
Emoji options markdown-pdf.emoji
Configuration options markdown-pdf.executablePath
Common Options markdown-pdf.scale
PDF options markdown-pdf.displayHeaderFooter resource
markdown-pdf.headerTemplate resource
markdown-pdf.footerTemplate resource
markdown-pdf.printBackground resource
markdown-pdf.orientation resource
markdown-pdf.pageRanges resource
markdown-pdf.format resource
markdown-pdf.width resource
markdown-pdf.height resource
markdown-pdf.margin.top resource
markdown-pdf.margin.bottom resource
markdown-pdf.margin.right resource
markdown-pdf.margin.left resource
PNG JPEG options markdown-pdf.quality
markdown-pdf.clip.x
markdown-pdf.clip.y
markdown-pdf.clip.width
markdown-pdf.clip.height
markdown-pdf.omitBackground
PlantUML options markdown-pdf.plantumlOpenMarker
markdown-pdf.plantumlCloseMarker
markdown-pdf.plantumlServer
markdown-it-include options markdown-pdf.markdown-it-include.enable
mermaid options markdown-pdf.mermaidServer

Save options

markdown-pdf.type

"markdown-pdf.type": [ "pdf", "html", "png", "jpeg" ],

markdown-pdf.convertOnSave

markdown-pdf.convertOnSaveExclude

"markdown-pdf.convertOnSaveExclude": [ "^work", "work.md$", "work|test", "[0-9][0-9][0-9][0-9]-work", "work\\test" // All '\' need to be written as '\\' (Windows) ],

markdown-pdf.outputDirectory

"markdown-pdf.outputDirectory": "C:\\work\\output",
"markdown-pdf.outputDirectory": "output",
"markdown-pdf.outputDirectory": "~/output",

markdown-pdf.outputDirectoryRelativePathFile

Styles options

markdown-pdf.styles

"markdown-pdf.styles": [ "C:\\Users\\<USERNAME>\\Documents\\markdown-pdf.css", "/home/<USERNAME>/settings/markdown-pdf.css", ],
"markdown-pdf.styles": [ "markdown-pdf.css", ],
"markdown-pdf.styles": [ "~/.config/Code/User/markdown-pdf.css" ],
"markdown-pdf.styles": [ "https://xxx/markdown-pdf.css" ],

markdown-pdf.stylesRelativePathFile

markdown-pdf.includeDefaultStyles

Syntax highlight options

markdown-pdf.highlight

markdown-pdf.highlightStyle

"markdown-pdf.highlightStyle": "github.css",

Markdown options

markdown-pdf.breaks

Emoji options

markdown-pdf.emoji

Configuration options

markdown-pdf.executablePath

"markdown-pdf.executablePath": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"

Common Options

markdown-pdf.scale

"markdown-pdf.scale": 1

PDF options

markdown-pdf.displayHeaderFooter

markdown-pdf.headerTemplate

markdown-pdf.footerTemplate

markdown-pdf.printBackground

markdown-pdf.orientation

markdown-pdf.pageRanges

"markdown-pdf.pageRanges": "1,4-",

markdown-pdf.format

"markdown-pdf.format": "A4",

markdown-pdf.width

markdown-pdf.height

"markdown-pdf.width": "10cm", "markdown-pdf.height": "20cm",

markdown-pdf.margin.top

markdown-pdf.margin.bottom

markdown-pdf.margin.right

markdown-pdf.margin.left

"markdown-pdf.margin.top": "1.5cm", "markdown-pdf.margin.bottom": "1cm", "markdown-pdf.margin.right": "1cm", "markdown-pdf.margin.left": "1cm",

PNG, JPEG options

markdown-pdf.quality

"markdown-pdf.quality": 100,

markdown-pdf.clip.x

markdown-pdf.clip.y

markdown-pdf.clip.width

markdown-pdf.clip.height

// x-coordinate of top-left corner of clip area "markdown-pdf.clip.x": 0, // y-coordinate of top-left corner of clip area "markdown-pdf.clip.y": 0, // width of clipping area "markdown-pdf.clip.width": 1000, // height of clipping area "markdown-pdf.clip.height": 1000,

markdown-pdf.omitBackground

PlantUML options

markdown-pdf.plantumlOpenMarker

markdown-pdf.plantumlCloseMarker

markdown-pdf.plantumlServer

markdown-it-include options

markdown-pdf.markdown-it-include.enable

mermaid options

markdown-pdf.mermaidServer

FAQ

How can I change emoji size ?

  1. Add the following to your stylesheet which was specified in the markdown-pdf.styles
.emoji { height: 2em; }

Auto guess encoding of files

Using files.autoGuessEncoding option of the Visual Studio Code is useful because it automatically guesses the character code. See files.autoGuessEncoding

"files.autoGuessEncoding": true,

Output directory

If you always want to output to the relative path directory from the Markdown file.

For example, to output to the "output" directory in the same directory as the Markdown file, set it as follows.

"markdown-pdf.outputDirectory" : "output", "markdown-pdf.outputDirectoryRelativePathFile": true,

Page Break

Please use the following to insert a page break.

<div class="page"/>

Known Issues

markdown-pdf.styles option

  • Online CSS (https://xxx/xxx.css) is applied correctly for JPG and PNG, but problems occur with PDF. #67

Release Notes

1.5.0 (2023/09/05)

  • Improve: The default date format for headers and footers has been changed to the ISO-based format (YYYY-MM-DD).
    • Support different date formats in templates #197
  • Improve: Avoid TimeoutError: Navigation timeout of 30000 ms exceeded and TimeoutError: waiting for Page.printToPDF failed: timeout 30000ms exceeded #266
  • Fix: Fix description of outputDirectoryRelativePathFile #238
  • README
    • Add: Specification Changes
    • Fix: Broken link

License

MIT

Special thanks

and