POST/api/v1/convert/markdown-to-pdf

Markdown to PDF

Convert Markdown into polished PDFs with configurable themes, syntax highlighting for code blocks, and automatic table of contents generation. Supports full GitHub-flavored Markdown including tables, task lists, and fenced code blocks.

Parameters

NameTypeRequiredDefaultDescription
markdownstringYes-Markdown content to convert. Supports GitHub-flavored Markdown.
themestringNogithubVisual theme: github, minimal, or modern.
enable_tocboolNofalseGenerate a table of contents from headings.
toc_depthintNo3Maximum heading depth for TOC. Range: 1-6.
enable_code_highlightboolNotrueEnable syntax highlighting for fenced code blocks.
code_stylestringNomonokaiSyntax highlighting theme (e.g., monokai, github, dracula, solarized).
page_sizestringNoA4Page size: A4, LETTER, LEGAL, TABLOID, A3, A5, etc.
orientationstringNoportraitPage orientation: portrait or landscape.
margin_topintNo20mmTop margin in millimeters.
margin_bottomintNo20mmBottom margin in millimeters.
margin_leftintNo20mmLeft margin in millimeters.
margin_rightintNo20mmRight margin in millimeters.

Code Examples

cURL
curl -X POST "https://app.alternapdf.com/api/v1/convert/markdown-to-pdf" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "markdown": "# Project README\n\n## Installation\n\n```bash\npip install my-package\n```\n\n## Features\n\n- Fast processing\n- Easy integration",
    "theme": "github",
    "enable_toc": true,
    "code_style": "monokai"
  }' \
  --output readme.pdf
Python
import requests

markdown_content = """
# Project README

## Installation

```bash
pip install my-package
```

## Features

- Fast processing
- Easy integration
- Full Markdown support
"""

response = requests.post(
    "https://app.alternapdf.com/api/v1/convert/markdown-to-pdf",
    headers={"X-API-Key": "YOUR_API_KEY"},
    json={
        "markdown": markdown_content,
        "theme": "github",
        "enable_toc": True,
        "code_style": "monokai"
    }
)

with open("readme.pdf", "wb") as f:
    f.write(response.content)
JavaScript
const markdownContent = `
# Project README

## Installation

\`\`\`bash
npm install my-package
\`\`\`

## Features

- Fast processing
- Easy integration
`;

const response = await fetch("https://app.alternapdf.com/api/v1/convert/markdown-to-pdf", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    markdown: markdownContent,
    theme: "github",
    enable_toc: true,
    code_style: "monokai",
  }),
});

fs.writeFileSync("readme.pdf", Buffer.from(await response.arrayBuffer()));

Response

Returns the PDF as a binary download with Content-Type: application/pdf.

HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="converted.pdf"
X-Credits-Used: 1
X-Credits-Remaining: 4999

<binary PDF data>