Use cURL to test the HTML to PDF API from a terminal, shell script, CI job, or backend task.
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.
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.pdfThese examples cover the next common production flows: generating from inline HTML with options and queuing a callback job.
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.pdfProvide 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"
}'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.
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.