generate_pdf
Generate a PDF from HTML, Markdown, a saved template, or a plain-English prompt, and get back a hosted link. Built for AI agents; backed by the PDFgen REST API.
Seeing file_gen:generate_pdf in your AI chat?
Your PDF wasn't created. Paste the text here and download it as a PDF.
Overview
generate_pdf is a tool exposed by the PDFgen MCP server. An agent passes exactly one source — html, markdown, template_id, or prompt — plus optional page settings, and receives an expiring URL to the rendered PDF.
Depending on the client, the tool is listed as generate_pdf, pdfgen:generate_pdf, or mcp__pdfgen__generate_pdf. They are the same tool.
Add the tool
Add the server to your MCP client config (Claude Desktop, Cursor, or any MCP client), using an API key from the Developer page, then restart the client. It runs via npx; nothing to host.
{"mcpServers": {"pdfgen": {"command": "npx","args": ["-y", "@pdfgen/mcp"],"env": {"PDFGEN_API_KEY": "pdfg_live_xxx"}}}}
Or start it directly over stdio:
PDFGEN_API_KEY=pdfg_live_xxx npx -y @pdfgen/mcp
Parameters
| Field | Type | Description |
|---|---|---|
| html | string | Raw HTML, optionally with {{handlebars}} tokens. One of html, markdown, template_id, or prompt. |
| markdown | string | Markdown, rendered with built-in typography. One of html, markdown, template_id, or prompt. |
| template_id | string | Id of a saved PDFgen template (see the list_templates tool). One of html, markdown, template_id, or prompt. |
| prompt | string | Plain-English description of the document (min 20 characters). The AI writes the HTML, then it's rendered. Billed at 2× the page rate. |
| data | object | Values merged into {{tokens}} in html or a template. Ignored for markdown and prompt. |
| engine | string | For html only: "handlebars" (default) or "legacy" to skip templating. |
| format | string | Page format: A4, Letter, Legal, A3, A5, Tabloid. Default A4. |
| orientation | string | "portrait" (default) or "landscape". |
| file_name | string | File name for the generated PDF, without extension. |
Examples
HTML with data
{"name": "generate_pdf","arguments": {"html": "<h1>Invoice {{number}}</h1><p>Bill to: {{customer}}</p>","data": { "number": "INV-1024", "customer": "Acme Inc" },"format": "Letter","file_name": "invoice-1024"}}
Markdown
{"name": "generate_pdf","arguments": {"markdown": "# Weekly report\n\n- Signups: 412\n- Churn: 1.8%","format": "A4"}}
Plain-English prompt
{"name": "generate_pdf","arguments": {"prompt": "A one-page certificate of completion for Jane Doe, course 'Intro to Data Science', dated Oct 29 2026, with a signature line.","orientation": "landscape"}}
Result & errors
On success the tool returns a text result containing the hosted link:
PDF generated: https://...signed-link...pdf
The link expires after 7 days. On failure the tool returns an error result with the API status and code, for example:
PDFgen API 429: {"code":"quota_exceeded","message":"..."}
Passing zero or more than one source returns Provide exactly one of `html`, `markdown`, `template_id`, or `prompt`. See Errors & rate limits for every error code.
REST equivalent
Not using MCP? generate_pdf is a thin wrapper around this endpoint, which also supports password protection, custom link expiry, and returning the PDF binary directly. See Generate a PDF.
curl -X POST https://pdfgen.com/api/v1/generate \-H "Authorization: Bearer pdfg_live_xxx" \-H "Content-Type: application/json" \-d '{"html": "<h1>Invoice {{number}}</h1>","data": { "number": "INV-1024" },"export_type": "url"}'# 200 OK{ "url": "https://...signed-link...pdf" }
Billing
Each successful call costs 1 credit per 5 pages; the prompt source costs double. Failed calls are free. The free plan includes 30 PDFs a month, no credit card required. See pricing.
Tool not available?
If your agent reports that a generate_pdf tool (for example file_gen:generate_pdf) doesn't exist or failed, it doesn't have a working PDF tool connected. Just need the document? Paste the text at the top of this page. Building an agent? Add the PDFgen MCP server using the config above, or call POST https://pdfgen.com/api/v1/generate directly with an API key.