Skip to main content
POST
/
pdf
Convert HTML to PDF
curl --request POST \
  --url https://api.example.com/pdf/ \
  --header 'Content-Type: application/json' \
  --data '
{
  "html": "<string>",
  "url": "<string>",
  "page_size": "<string>",
  "landscape": true,
  "margin_top": "<string>",
  "margin_bottom": "<string>",
  "margin_left": "<string>",
  "margin_right": "<string>",
  "print_background": true,
  "scale": 123
}
'
{
  "id": "<string>",
  "status": "<string>",
  "created_at": "<string>"
}

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
string
required
HTML content to convert. Must be valid HTML.
url
string
URL to render instead of HTML content. Cannot be used with html.
page_size
string
default:"A4"
Page size. Options: A4, Letter, Legal, A3, A5
landscape
boolean
default:"false"
Render in landscape orientation
margin_top
string
default:"1cm"
Top margin (CSS units: px, cm, in, mm)
margin_bottom
string
default:"1cm"
Bottom margin
margin_left
string
default:"1cm"
Left margin
margin_right
string
default:"1cm"
Right margin
print_background
boolean
default:"true"
Include background colors and images
scale
number
default:"1.0"
Scale factor (0.1 to 2.0)

Response

id
string
Unique conversion identifier
status
string
Conversion status: pending, processing, completed, failed
created_at
string
ISO 8601 timestamp

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."
}