cURL HTML to PDF API guide

Use cURL to test the HTML to PDF API from a terminal, shell script, CI job, or backend task.

EndpointPOST https://api.html2pdf.app/v1/generate
AuthenticationX-API-Key: <your-api-key>

Overview

Generate PDFs from URLs or raw HTML with cURL before wiring the same request into your application code.

The API accepts a JSON request body. Send either a public URL or inline HTML in the required html parameter. For normal synchronous conversions, the response body is the generated PDF and should be saved as binary data.

Requirements

  • cURL 7.61 or newer
  • An html2pdf.app API key
  • A terminal that can write the PDF response to a file

Quick start

Replace <your-api-key> or the environment variable with your html2pdf.app API key, then run the example from a trusted backend environment.

Send a public web page URL in the html field and write the binary response directly to document.pdf.

curl -X POST https://api.html2pdf.app/v1/generate \
-H 'Content-Type: application/json' \
-H 'X-API-Key: <your-api-key>' \
-d '{
  "html": "https://www.example.com"
}' \
--output document.pdf

cURL examples

These examples cover the next common production flows: generating from inline HTML with options and queuing a callback job.

1. Generate a PDF from inline HTML

Use raw HTML when the page is assembled by your application and does not have a public URL.

curl -X POST https://api.html2pdf.app/v1/generate \
-H 'Content-Type: application/json' \
-H 'X-API-Key: <your-api-key>' \
-d '{
  "html": "<h1>Invoice INV-1042</h1><p>Total: $240.00</p>",
  "format": "A4",
  "marginTop": 40,
  "marginRight": 32,
  "marginBottom": 40,
  "marginLeft": 32
}' \
--output invoice.pdf

2. Queue a conversion with a callback

Provide callBackUrl when the PDF should be generated in the background and posted back to your service.

curl -X POST https://api.html2pdf.app/v1/generate \
-H 'Content-Type: application/json' \
-H 'X-API-Key: <your-api-key>' \
-d '{
  "html": "https://www.example.com/report",
  "callBackUrl": "https://your-app.com/webhooks/pdf",
  "state": "report-1042"
}'

Request options

Most integrations start with html and then add options as the document design becomes more specific.

  • html is required and accepts a public URL or raw HTML.
  • format, landscape, width, and height control page size.
  • marginTop, marginRight, marginBottom, and marginLeft control whitespace around the rendered page.
  • media selects screen or print CSS rendering.
  • callBackUrl switches the request to asynchronous generation and sends the completed PDF to your webhook.

See the full API parameter reference for every supported field.

Troubleshooting

  • Use --fail-with-body in scripts so non-2xx responses fail the command.
  • Keep the API key in an environment variable instead of shell history.
  • Use --output for synchronous requests because the response body is the PDF file.

If the generated document is blank or missing styles, first confirm that the source URL is public and that required CSS, fonts, and images are reachable by the rendering service.