POST
/api/v1/convert/markdown-to-pdfMarkdown 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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| markdown | string | Yes | - | Markdown content to convert. Supports GitHub-flavored Markdown. |
| theme | string | No | github | Visual theme: github, minimal, or modern. |
| enable_toc | bool | No | false | Generate a table of contents from headings. |
| toc_depth | int | No | 3 | Maximum heading depth for TOC. Range: 1-6. |
| enable_code_highlight | bool | No | true | Enable syntax highlighting for fenced code blocks. |
| code_style | string | No | monokai | Syntax highlighting theme (e.g., monokai, github, dracula, solarized). |
| page_size | string | No | A4 | Page size: A4, LETTER, LEGAL, TABLOID, A3, A5, etc. |
| orientation | string | No | portrait | Page orientation: portrait or landscape. |
| margin_top | int | No | 20mm | Top margin in millimeters. |
| margin_bottom | int | No | 20mm | Bottom margin in millimeters. |
| margin_left | int | No | 20mm | Left margin in millimeters. |
| margin_right | int | No | 20mm | Right 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.pdfPython
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>