Salta al contenuto principale

PDF Tools API

HTML in PDF API

Integra convertire HTML in PDF nel backend, nei batch o nel prodotto senza mantenere un servizio PDF proprietario.

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

Usalo per renderizzare report, ricevute, estratti o viste interne lato server. Lo strumento web è per revisione manuale; l’API è per automazioni ripetibili lato server.

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

Il JSON o multipart non contiene HTML, URL o file richiesto.

401invalid_api_key

L’header x-api-key manca, non è valido o è stato ruotato.

402insufficient_credits

L’account non ha API Credits sufficienti.

502conversion_failed

Il rendering lato server non ha completato la conversione. I Credits vengono restituiti automaticamente in caso di errore.

Limits

  • Serve un PDF valido o dati di input corretti.
  • Chiama l’API dal server per non esporre la API Key nel browser.
  • Prova file rappresentativi prima di elaborare grandi lotti.

Response headers

html-to-pdf.pdf con header che indicano Credits usati e saldo rimanente.

Content-Type
Tipo MIME del file generato, di solito application/pdf o application/zip.
Content-Disposition
Nome di download del file generato.
X-Credits-Charged
Credits addebitati per la richiesta riuscita.
X-Credit-Balance
Saldo API Credits dopo la richiesta.

FAQ

Quanto costa HTML in PDF API?

Le richieste riuscite usano API Credits; gli errori di elaborazione vengono rimborsati automaticamente. Ogni utente con accesso riceve 100 free API Credits al mese, e 1,000 Credits = $1.

Gli strumenti web usano API Credits?

No. Gli strumenti che lavorano nel browser non consumano API Credits. Contano solo le chiamate con API Key.

Posso chiamare l’API dal browser?

Non è consigliato. Tieni la API Key nel backend, in una coda o in un job lato server.

Start with 100 free API Credits

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