Convert HTML to PDF
Convert HTML content to a PDF document.
This endpoint returns immediately with a 202 Accepted status. The PDF is generated asynchronously. Use the Get Conversion endpoint to check status and retrieve the PDF URL.
Request
HTML content to convert. Must be valid HTML.
URL to render instead of HTML content. Cannot be used with html.
Page size. Options: A4, Letter, Legal, A3, A5
Render in landscape orientation
Top margin (CSS units: px, cm, in, mm)
Include background colors and images
Scale factor (0.1 to 2.0)
Response
Unique conversion identifier
Conversion status: pending, processing, completed, failed
Examples
Basic HTML Conversion
curl -X POST https://api.pdflet.dev/api/v1/pdf/ \
-H "X-API-Key: pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"html": "<html><body><h1>Hello World</h1></body></html>"
}'
With Custom Options
curl -X POST https://api.pdflet.dev/api/v1/pdf/ \
-H "X-API-Key: pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"html": "<html><body><h1>Report</h1></body></html>",
"page_size": "Letter",
"landscape": true,
"margin_top": "2cm",
"margin_bottom": "2cm",
"print_background": true
}'
Response
{
"id": "conv_abc123def456",
"status": "pending",
"created_at": "2024-01-15T10:30:00Z"
}
Error Responses
Invalid HTML
{
"error": "validation_error",
"message": "Either 'html' or 'url' is required"
}
No Credits
{
"error": "insufficient_credits",
"message": "You have no credits remaining. Please upgrade your plan."
}