Markdown to PDF

Learn

Automate PDF Generation with the API

Generate branded PDFs from your own applications, scripts, and workflows using the Markdown-to-PDF API.

Published 2026-05-03 · Updated 2026-05-03

Automate PDF Generation with the API

The Markdown-to-PDF API lets you generate PDFs programmatically from any application that can make HTTP requests. Use it to automate report generation, invoice creation, document pipelines, and more.

Getting an API Key

  1. Sign in to your account.
  2. Go to Dashboard → API Keys.
  3. Click New Key, give it a name, and copy the generated key.
  4. Store it securely — it’s shown only once.

Each API key has its own usage tracking, so you can create separate keys for development, staging, and production.

Your First API Call

The endpoint is a single POST request:

curl -X POST https://markdowntopdfconverter.com/api/v1/convert \
  -H "Authorization: Bearer mp_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "markdown": "# Quarterly Report\n\nRevenue grew **15%** this quarter.",
    "templateId": "executive",
    "options": { "pageNumbers": true }
  }' \
  -o report.pdf

The response is a PDF file. That’s it — one request, one PDF.

Request Parameters

Parameter Required Description
markdown Yes The Markdown content. Max 200,000 characters.
templateId No Template to use: clean, executive, resume, academic, legal, creative. Default: clean.
filename No Name for the downloaded file. Default: document.pdf.
locale No Locale for rendering. Supports all 12 languages including ar, ja, zh-CN. Default: en.
customTemplateId No UUID of a saved custom template. Must be owned by the API key’s user.
options No pageNumbers (boolean), bodyTextColor (hex), headingTextColor (hex), creativeAccent (slate/purple/blue/emerald/rose/amber).

Code Examples

Python

import requests

api_key = "mp_live_YOUR_API_KEY"
headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

payload = {
    "markdown": "# Invoice\n\n**Amount:** $1,200\n\n| Item | Qty | Price |\n| --- | --- | --- |\n| Widget | 5 | $240 |",
    "templateId": "clean",
    "options": {"pageNumbers": True}
}

response = requests.post(
    "https://markdowntopdfconverter.com/api/v1/convert",
    json=payload,
    headers=headers
)

with open("invoice.pdf", "wb") as f:
    f.write(response.content)

JavaScript (Node.js)

const apiKey = "mp_live_YOUR_API_KEY";

const response = await fetch(
  "https://markdowntopdfconverter.com/api/v1/convert",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      markdown: "# Meeting Notes\n\n- Action item 1\n- Action item 2",
      templateId: "clean",
      filename: "meeting-notes",
    }),
  }
);

const buffer = await response.arrayBuffer();
await fs.writeFile("meeting-notes.pdf", Buffer.from(buffer));

Using Custom Templates via API

If you have saved custom templates, reference them by ID:

{
  "markdown": "# Branded Report",
  "templateId": "clean",
  "customTemplateId": "11111111-1111-4111-a111-111111111111"
}

The API verifies that the custom template belongs to your account. Other users’ templates return a 404.

Error Handling

Status Meaning Action
200 Success PDF in response body
400 Invalid request Check JSON format and parameters
401 Invalid API key Verify key is active and correctly formatted
402 Credits exhausted Purchase more credits from dashboard
404 Template not found Check customTemplateId
415 Wrong Content-Type Use application/json
429 Rate limited Wait and retry with exponential backoff

Pricing

API calls consume credits. Each successful conversion uses 1 credit.

Tier Monthly Calls Price
Free 25 $0
Starter 500 $9
Pro 2,000 $29

Purchase credits from your dashboard. Unused free-tier calls reset monthly.

Common Automation Patterns

Generate Reports on a Schedule

Use a cron job or scheduled task to generate daily/weekly reports:

#!/bin/bash
# Daily report generator
MARKDOWN=$(generate_daily_report)
curl -X POST https://markdowntopdfconverter.com/api/v1/convert \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"markdown\":$(echo "$MARKDOWN" | jq -Rs .),\"templateId\":\"executive\",\"options\":{\"pageNumbers\":true}}" \
  -o "report-$(date +%Y-%m-%d).pdf"

Batch Document Generation

Process multiple documents by iterating over a list:

documents = [
    {"markdown": "# Doc 1", "templateId": "clean"},
    {"markdown": "# Doc 2", "templateId": "executive"},
]

for doc in documents:
    response = requests.post(API_URL, json=doc, headers=headers)
    response.raise_for_status()
    # Save each PDF

Next Steps

  • Learn how to build custom templates that match your brand.
  • Check the full API documentation for complete endpoint reference.
  • Set up usage monitoring from your dashboard to track API call volume.