Skip to main content

PDF Tools API

HTML to PDF API

Render trusted HTML into PDFs from your backend for reports, receipts, statements, and generated documents.

Credits

1 Credit / call

1 Credit per successful API request. Failed processing attempts are refunded automatically.

Pricing

1,000 Credits = $1

Every signed-in user receives 100 free API Credits each month.

Endpoint

/api/external/html-to-pdf/pdf

Use your API Key in the x-api-key header.

Use case

Use it when your application already renders HTML and needs durable PDF output for email, storage, or compliance workflows.

cURL example

curl -X POST https://itextmaster.com/api/external/html-to-pdf/pdf \
  -H 'x-api-key: YOUR_API_KEY' \
  -F 'html=@index.html;type=text/html' \
  -F 'pageSize=A4' \
  -F 'printBackground=true' \
  --output html-to-pdf.pdf

Multipart example

curl -X POST https://itextmaster.com/api/external/html-to-pdf/pdf \
  -H 'x-api-key: YOUR_API_KEY' \
  -F 'html=@index.html;type=text/html' \
  -F 'pageSize=A4' \
  -F 'printBackground=true' \
  --output html-to-pdf.pdf

JSON base64 example

curl -X POST https://itextmaster.com/api/external/html-to-pdf/pdf \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
    "html": "<!doctype html><html><body><h1>Report</h1></body></html>",
    "pageSize": "A4",
    "printBackground": true
  }' \
  --output html-to-pdf.pdf

Node.js example

import { writeFile } from 'node:fs/promises';

const response = await fetch('https://itextmaster.com/api/external/html-to-pdf/pdf', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': process.env.ITEXTMASTER_API_KEY
  },
  body: JSON.stringify({
  html: '<!doctype html><html><body><h1>Report</h1></body></html>',
  pageSize: 'A4',
  printBackground: true
})
});

if (!response.ok) {
  throw new Error(await response.text());
}

await writeFile('html-to-pdf.pdf', Buffer.from(await response.arrayBuffer()));

Python example

import os
import requests

response = requests.post(
    'https://itextmaster.com/api/external/html-to-pdf/pdf',
    headers={
        'Content-Type': 'application/json',
        'x-api-key': os.environ['ITEXTMASTER_API_KEY'],
    },
    json={
        'html': '<!doctype html><html><body><h1>Report</h1></body></html>',
        'pageSize': 'A4',
        'printBackground': True,
    },
)
response.raise_for_status()

with open('html-to-pdf.pdf', 'wb') as f:
    f.write(response.content)

Error codes

400invalid_payload

The JSON or multipart payload is missing required HTML or URL input.

401invalid_api_key

The x-api-key header is missing, invalid, or has been rotated.

402insufficient_credits

The account does not have enough API Credits for the request.

502conversion_failed

The server-side rendering service could not complete the conversion. Failed processing attempts are refunded automatically.

Limits

  • HTML input is sanitized before rendering.
  • Maximum HTML payload is 500 KB.
  • Server-side rendering may reject unsupported or unsafe embedded resources.

Response headers

html-to-pdf.pdf with Credits response headers.

Content-Type
The MIME type of the generated file, usually application/pdf or application/zip.
Content-Disposition
Attachment filename for the generated output.
X-Credits-Charged
Credits charged for the successful request.
X-Credit-Balance
Remaining API Credit balance after the request.

FAQ

How much does the HTML to PDF API cost?

Each successful HTML to PDF API request uses 1 Credit. 1,000 Credits cost $1, and every signed-in user receives 100 free API Credits each month.

What happens if processing fails?

Failed processing attempts are refunded automatically, and the API returns an error response you can log or retry.

Should I call this API from the browser?

No. Keep API Keys server-side and call the endpoint from your backend, queue, or automation job when you need to render HTML to PDF.

Start with 100 free API Credits

Create an API Key, test HTML to PDF API, and buy more Credits only when automation volume grows.