text-to-pdf

Markdown to PDF

Convert CommonMark and GFM Markdown into a typeset PDF with syntax-highlighted code blocks, equation rendering and a generated table of contents.

Format facts

Source MIME
text/markdown
Target MIME
application/pdf
Max input size
5 MB
Typical output size
8-20x input size for text to typeset PDF
Lossy?
No
Backed by
markdown-to-pdf
Availability
Live public API
Endpoint
POST /api/v1/markdown-to-pdf

How the conversion runs

  1. Step 1. POST a JSON body to /api/v1/markdown-to-pdf; the request is capped and validated with a strict schema before queueing.
  2. Step 2. The worker parses CommonMark and GFM Markdown, sanitizes any allowed inline HTML, then renders print HTML.
  3. Step 3. Chromium prints the sanitized document to PDF with the selected theme and deterministic page settings.

API example

curl -X POST https://api.docushell.com/api/v1/markdown-to-pdf \
  -H "Authorization: Bearer $DOCUSHELL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"markdown":"# Quarterly notes\n\nShip the PDF."}'

Submit returns a queued job with job_id. Poll GET /api/v1/jobs/{id}, then download with GET /api/v1/jobs/{id}/download.

Format-specific quirks

  • Inline raw HTML is sanitized because untrusted Markdown is a common XSS vector.
  • Math is rendered server-side with KaTeX; ambiguous single-dollar inline math is disabled by default.
  • Relative image paths are rejected. Use base64 data URIs or absolute HTTPS URLs.

Frequently asked questions

Which Markdown dialect is supported?

CommonMark with GFM tables, task lists and strikethrough is supported.

Can I use a custom CSS theme?

Use a bundled theme name in the request. Arbitrary user CSS is not accepted for security reasons.

How are remote images handled?

Remote HTTPS images pass through the same SSRF guard used by webpage-to-pdf.

Related conversions