Send a complete HTML document (CSS included) and receive it back as a PDF file, base64 encoded. Each successful render costs one file credit from your plan.
Every request needs your API secret key in theAuthorization header as a Bearer token. Your email must be verified and your plan must include this feature with credit remaining.
Authorization: Bearer pigdf_your_api_secret_keyThe body is JSON with a required content field holding your HTML, and an optional options object.
curl -X POST https://pigdf.com/api/render/html-to-pdf/ \
-H "Authorization: Bearer pigdf_your_api_secret_key" \
-H "Content-Type: application/json" \
-d '{
"content": "<h1>Hello PDF</h1>",
"options": {
"page_size": { "width": 794, "height": 1123 },
"tagged": true
}
}'Every option is optional. This example sends all of them at once, with each default noted. Leave options out entirely and you get an A4 portrait document with backgrounds printed at normal scale.
{
"content": "<h1>Invoice #1024</h1>", // required: your full HTML document (up to 25 MB)
"options": {
"page_size": { "width": 794, "height": 1123 }, // default: A4. Both 1-20000 px. Delete this for A4.
"landscape": false, // default: false (portrait). Safe to delete.
"margin": { "top": 40, "right": 40, "bottom": 40, "left": 40 }, // default: none. 0-20000 px per side. Include only the sides you want. Safe to delete.
"scale": 1, // default: 1. Range 0.1-2. Safe to delete.
"tagged": true, // default: false. Tagged, accessible PDF. Safe to delete.
"outline": true // default: false. Embeds an outline from your headings. Safe to delete.
}
}
// JSON does not allow comments. Remove the comments above before sending.| Option | Type | Required | Default | Example | Notes |
|---|---|---|---|---|---|
| page_size | object | No | A4 | { "width": 794, "height": 1123 } | Custom page size as width and height in pixels, both between 1 and 20000. |
| tagged | boolean | No | false | true | Produces a tagged, accessible PDF that screen readers understand. |
| outline | boolean | No | false | true | Embeds a document outline built from your headings. |
| landscape | boolean | No | false | true | Landscape orientation instead of portrait. |
| scale | number | No | 1 | 0.8 | Rendering scale between 0.1 and 2. |
| margin | object | No | none | { "top": 40, "left": 40 } | Page margins as top, right, bottom, and left in pixels, each between 0 and 20000. Include only the sides you need. |
Every response uses the same envelope: success, errors, and data. On success the PDF arrives base64 encoded in data.content; decode it and save it as a file.
{
"success": true,
"errors": [],
"data": {
"content": "JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9..."
}
}When something is wrong, success is false, data is empty, and errors holds one or more messages. The HTTP status tells you the category.
{
"success": false,
"errors": ["Your current plan does not include this feature."],
"data": {}
}| Status | When it happens | Message |
|---|---|---|
| 400 | The body is not valid JSON. | Invalid JSON. |
| 400 | The content field is missing or empty. | A non-empty "content" field is required. |
| 401 | The API secret key is missing or wrong. | You are not authorized to use this API. |
| 403 | Your email is not verified. | Please verify your email address to use this API. |
| 403 | Your plan does not include this feature. | Your current plan does not include this feature. |
| 408 | The render took longer than 30 seconds. | Rendering took longer than 30 seconds. |
| 413 | The HTML you sent, or the PDF produced, is larger than 25 MB. | The content exceeds the 25 MB limit. |
| 429 | You have used all your credit for this feature. | You have used all your credit for this feature. |
| 502 | The HTML could not be rendered. | The content could not be rendered to a PDF. |
The HTML you send and the PDF you receive are each limited to 25 MB.
Rendering is limited to 30 seconds per request.
Failed requests never spend a credit. Only a successful render does.