catalogue / tools / Documents / Markdown to PDF

Convert Markdown to PDF

To convert Markdown to PDF, send one POST to /v1/markdown-to-pdf with the Markdown source. Each call costs $0.005 in USDC on Base via x402, with no account and no API key. The source file can be up to 2 MB.

Endpoint
POST /v1/markdown-to-pdf
Price
$0.005 per call

01Limits

LimitValue
Largest source file2 MB (2,097,152 bytes)
Timeout12 s
Source formatsMarkdown
Output formatsPDF
Option formatone of "A3", "A4", "A5", "Letter", "Legal", "Tabloid"; default "A4"
Option landscapedefault false

02Example

A real Markdown to PDF run of markdown-to-pdf.

Request
POST /v1/markdown-to-pdf
content-type: application/json
payment-signature: <base64 x402 payload>

{
  "url": "https://grist.tools/samples/documents/render-notes.md",
  "format": "A4",
  "landscape": false
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/documents/render-notes.md",
  "pages": 1,
  "bytes": 69844,
  "format": "A4",
  "landscape": false,
  "pdf_base64": "JVBERi0xLjcKJYGBgYEKCjkgMCBvYmoKPDwKL0ZpbHRlciAvRmxhdGVEZWNvZGUK...",
  "rendered_at": "2026-09-01T12:00:00.000Z"
}

Source file: documents/render-notes.md, 647 bytes. Markdown field notes with headings, an ordered list, a table, emphasis, a fenced code block and a blockquote. The request sets format to "A4" and landscape to false. The recorded run returned 68.2 KB (69,844 bytes) of PDF, 108 times the source size, with 1 page. Decoded, the PDF in pdf_base64 opens with 25 50 44 46 2D 31 2E 37 0A 25 81 81 (ASCII PDF). Recorded with chromium 153.0.8010.36.

In the sample itself, the Markdown source has 4 headings (1 at level 1, 3 at level 2) reading "Rain Gauge Field Notes", "Method", "Readings" and "Summary", 3 numbered list items, 6 pipe table rows, header included, 1 fenced code block and 1 blockquote line. Inline, it marks 1 bold span and 1 italic span, with no link. In the returned PDF: the file opens with the header line %PDF-1.7, then a comment of four bytes above 0x7F that marks the file as binary. The first object in the file is number 9, generation 0, a stream compressed with FlateDecode.

03Format notes

Markdown as a source

Markdown can be sent inline or fetched from a URL for markdown-to-pdf. Plain text has no signature, so the fetched body is checked for NUL bytes, whose presence means the content is binary, before decoding. Parsing uses markdown-it with html disabled, linkify enabled, and typographer and breaks switched off. Raw HTML embedded in the Markdown is therefore escaped and shown as text rather than rendered; a caller who needs raw HTML rendered uses the HTML route instead. Bare URLs become links that stay inert in the PDF and are never fetched. Image syntax that points at an external address is not loaded either, because the renderer aborts sub-resource requests, while raster data images written inline are accepted and SVG data images are blocked. Exactly one of url or markdown must be supplied.

PDF as a target

HTML and Markdown reach PDF through one shared Chromium renderer. The document is handed to the browser as a string, never as a URL to navigate, JavaScript is disabled, and every interceptable sub-resource request is aborted, so external stylesheets, web fonts and remote images do not appear in the output. Paper size comes from a closed enum shared by both services, and a landscape flag switches orientation. For Markdown, markdown-it escapes raw HTML, and a built-in print stylesheet using system fonts supplies the page margins, since the renderer sets none. After rendering, pdf-lib saves the file again with pinned creation and modification dates and grist.tools as producer and creator, dropping the document ID, so the same input yields the same bytes for a given Chromium version.

04Errors

CodeHTTP
invalid_input400
blocked_target403
unreachable_target424
upstream_timeout424
unsupported_content_type415
too_large413
unprocessable422
internal500

When each is raised, and what it means for payment: /docs/markdown-to-pdf.

05Questions

What does it cost to convert Markdown to PDF?
$0.005 per call, paid in USDC on Base via x402.
How large can the Markdown file be?
Up to 2 MB (2,097,152 bytes). Past a limit the call answers too_large (413).
What happens if the conversion fails?
The tool answers with a typed JSON error from the errors table. Payment is settled only after the tool has produced its result; a call that fails inside the tool is never settled.

06Related