UtilitiesGenerate PDF
PDF Endpoints
Generate PDF
Generate PDFs from HTML content or any URL. Pages are rendered using a real browser engine, converted to PDF, and uploaded to cloud storage. Returns a public download URL.
POST
/v1/pdf/htmlGenerate a PDF from HTML content. The HTML is rendered in a browser, printed to PDF, and the resulting file is uploaded to cloud storage.
Request Body
| Parameter | Type | Description |
|---|---|---|
htmlrequired | string | Complete HTML content to convert to PDF |
title | string | Title used for the exported filename |
pageSize | "A4" | "Letter" | "Legal" | Page size. Defaults to "A4" |
landscape | boolean | Landscape orientation. Defaults to false |
margin | object | Page margins with top, right, bottom, left (e.g., "20mm") |
printBackground | boolean | Print background graphics and colors. Defaults to true |
timeoutMs | number | Timeout in milliseconds (${API_CONFIG.pdf.minTimeoutMs}-${API_CONFIG.pdf.maxTimeoutMs}). Defaults to ${API_CONFIG.pdf.defaultTimeoutMs} |
Example Request
Example Response
POST
/v1/pdf/urlNavigate to a URL with a real browser, render the page, and convert it to PDF. Useful for generating PDFs from live webpages, invoices, reports, or dashboards.
Request Body
| Parameter | Type | Description |
|---|---|---|
urlrequired | string | URL to navigate to and convert to PDF |
title | string | Title used for the exported filename |
pageSize | "A4" | "Letter" | "Legal" | Page size. Defaults to "A4" |
landscape | boolean | Landscape orientation. Defaults to false |
margin | object | Page margins with top, right, bottom, left (e.g., "20mm") |
printBackground | boolean | Print background graphics and colors. Defaults to true |
timeoutMs | number | Timeout in milliseconds (${API_CONFIG.pdf.minTimeoutMs}-${API_CONFIG.pdf.maxTimeoutMs}). Defaults to ${API_CONFIG.pdf.defaultTimeoutMs} |
Example Request
Example Response
Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Whether PDF generation succeeded |
url | string | Public download URL of the generated PDF |
error | string | Error message if generation failed |
durationMs | number | Total time taken in milliseconds |
cost | number | Cost of the request in USD |
Margin Object
The
margin parameter accepts an object with CSS-style margin values:| Field | Type | Description |
|---|---|---|
top | string | Top margin (e.g., "20mm", "1in") |
right | string | Right margin |
bottom | string | Bottom margin |
left | string | Left margin |
Error Response
When PDF generation fails, the response will include
success: false with an error message: