HTML to PDF.One request away.

Back

HTML to PDF

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.

Authentication

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_key

Endpoint

POSThttps://pigdf.com/api/render/html-to-pdf/

Request

The 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
    }
  }'

All options, annotated

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.

Options

OptionTypeRequiredDefaultExampleNotes
page_sizeobjectNoA4{ "width": 794, "height": 1123 }Custom page size as width and height in pixels, both between 1 and 20000.
taggedbooleanNofalsetrueProduces a tagged, accessible PDF that screen readers understand.
outlinebooleanNofalsetrueEmbeds a document outline built from your headings.
landscapebooleanNofalsetrueLandscape orientation instead of portrait.
scalenumberNo10.8Rendering scale between 0.1 and 2.
marginobjectNonone{ "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.

Response

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..."
  }
}

Errors

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": {}
}
StatusWhen it happensMessage
400The body is not valid JSON.Invalid JSON.
400The content field is missing or empty.A non-empty "content" field is required.
401The API secret key is missing or wrong.You are not authorized to use this API.
403Your email is not verified.Please verify your email address to use this API.
403Your plan does not include this feature.Your current plan does not include this feature.
408The render took longer than 30 seconds.Rendering took longer than 30 seconds.
413The HTML you sent, or the PDF produced, is larger than 25 MB.The content exceeds the 25 MB limit.
429You have used all your credit for this feature.You have used all your credit for this feature.
502The HTML could not be rendered.The content could not be rendered to a PDF.

Limits

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.