Generate PDF
POST https://api.getdocuforge.dev/v1/generate
Generate a pixel-perfect PDF from HTML or a saved template.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
html | string | Either html or template | Raw HTML to convert to PDF |
template | string | Either html or template | Template ID (tmpl_xxx) |
data | object | No | Data to merge into template variables |
options | object | No | PDF rendering options (see below) |
output | string | No | "url" (default) or "base64" |
webhook | string | No | URL to POST when generation completes |
Options
| Parameter | Type | Default | Description |
|---|---|---|---|
format | string or object | "A4" | "A4", "Letter", "Legal", or { width, height } |
margin | string or object | "0.5in" | Uniform margin string or { top, right, bottom, left } |
orientation | string | "portrait" | "portrait" or "landscape" |
header | string | — | HTML for page header. Supports {{pageNumber}} and {{totalPages}} |
footer | string | — | HTML for page footer. Supports {{pageNumber}} and {{totalPages}} |
printBackground | boolean | true | Include background colors/images |
Example — HTML Mode
Example — Template Mode
Response
Errors
| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR | Invalid request body |
| 401 | UNAUTHORIZED | Invalid or missing API key |
| 403 | USAGE_LIMIT_EXCEEDED | Monthly PDF limit reached |
| 429 | RATE_LIMITED | Too many requests |
| 500 | INTERNAL_ERROR | Server error during rendering |

