PigDF Logo

PigDF

HTML to PDF

Convert an HTML document, including its CSS and JavaScript, into a PDF file. This is the only endpoint PigDF exposes.

Endpoint

POST https://pigdf.com/api/html-to-pdf

Requires a valid API key (see Introduction) and an active subscription whose plan includes the HTML to PDF functionality.

Request body

Send a JSON body with these fields:

Field Type Description
content string Required. The full HTML document, with its CSS and JavaScript inline. Maximum 10 MB.
settings object Optional. Rendering options.
settings.page_size object Optional. The page dimensions, given in pixels. If you do not send page_size, the PDF uses A4 size by default.
settings.page_size.width number Page width in pixels. Required when page_size is given.
settings.page_size.height number Page height in pixels. Required when page_size is given.

Example request body:

{
  "content": "<h1>Invoice</h1>",
  "settings": {
    "page_size": { "width": 794, "height": 1123 }
  }
}

794 × 1123 px is roughly A4 at 96 DPI. Backgrounds are always printed, and any JavaScript in your HTML runs before the page is captured.

Response

Every response uses the same JSON envelope, on success and on error:

Field Type Description
status boolean true when the PDF was generated, false on any error.
errors array A list of { "type": ..., "message": ... } objects. Empty on success.
content string or null On success, the base64-encoded PDF. null on error.

Success:

{
  "status": true,
  "errors": [],
  "content": "JVBERi0xLjQKJeLjz9MK..."
}

Error:

{
  "status": false,
  "errors": [
    { "type": "subscription", "message": "You do not have an active subscription." }
  ],
  "content": null
}

Decoding the PDF

JSON cannot carry raw bytes, so the PDF is returned as a base64 string in content. To get a usable file you must base64-decode that string and write the result to a .pdf file. Always check that status is true first.

curl https://pigdf.com/api/html-to-pdf \
  -H "Authorization: Bearer pigdf_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": "<h1>Hello, PigDF</h1>", "settings": {"page_size": {"width": 794, "height": 1123}}}' \
  | jq -r '.content' | base64 --decode > document.pdf

The cURL example assumes success; it needs jq and base64 installed.

Errors

On failure, status is false and errors describes what went wrong. Each error has a type:

type HTTP Meaning
authentication 401 Missing or invalid API key.
subscription 403 No active subscription on your account.
functionality 403 Your plan does not include HTML to PDF.
usage_limit 429 You have reached your plan's usage limit for this feature.
request 400 Invalid JSON, missing content, or invalid page size.
request 413 The content is larger than 10 MB.
render 408 Rendering took longer than 30 seconds.
render 502 The content could not be rendered.
render 413 The generated PDF is larger than 10 MB.

Limits & behavior