PDFDispatch Docs

Markdown to PDF

Write in Markdown, style with HTML and CSS. You send a small HTML template and the Markdown files; each placeholder in the template is replaced by the rendered Markdown.

POST https://api.pdfdispatch.com/v1/convert/markdown

Form fields

FieldTypeDefaultWhat it does
index.html requiredfile–A page with a placeholder for each Markdown file: {{ toHTML "notes.md" }}. Its CSS styles the result.
*.md requiredfile–One or more Markdown files, named in index.html. A name that index.html asks for but you did not send is an error (400).
any other filefile–Images, stylesheets and fonts, by file name, as for HTML.

Page options (paper, margins, header and footer, waiting) are the same as for HTML:

FieldTypeDefaultWhat it does
paperWidth, paperHeightsize8.5 × 11 (US Letter)The paper size. A number is inches; add a unit for others: 210mm, 29.7cm, 595pt, 794px, 50pc. A4 is 210mm × 297mm.
marginTop, marginBottom, marginLeft, marginRightsize0.39 (1 cm)The page margins, in the same units. A header or footer is drawn inside the top or bottom margin.
landscapebooleanfalseTurn the paper sideways.
printBackgroundbooleanfalsePrint background colours and images. Without it, most backgrounds are left out, as a browser does when it prints.
preferCssPageSizebooleanfalseUse the size from the page’s CSS @page rule instead of paperWidth and paperHeight.
waitDelayduration–Wait this long after the page has loaded before printing, for example 500ms or 2s. See Waiting for better ways.
emulatedMediaTypestringprintprint or screen: which CSS media rules apply.

All of them: Rendering options.

The template

index.html is an ordinary page with one placeholder per Markdown file, written as {{ toHTML "file name" }}:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="notes.css">
  </head>
  <body>
    <header><img src="logo.png" alt=""></header>
    <main>{{ toHTML "meeting-notes.md" }}</main>
  </body>
</html>

The Markdown supports the common extensions: tables, fenced code blocks, strikethrough, automatic links, heading ids and definition lists. Raw HTML inside the Markdown is cleaned: safe tags such as <sup> stay, scripts and event handlers are removed. Put anything that needs scripts in the template instead.

Example

curl --fail-with-body \
  --header "Authorization: Bearer $PDD_KEY" \
  --form files=@index.html \
  --form files=@notes.css \
  --form files=@logo.png \
  --form files=@meeting-notes.md \
  --form paperWidth=210mm --form paperHeight=297mm \
  --output meeting-notes.pdf \
  https://api.pdfdispatch.com/v1/convert/markdown

Several Markdown files can go into one template ({{ toHTML "part-1.md" }} … {{ toHTML "part-2.md" }}). For one PDF per Markdown file, send one request per file.