Documentation

POST /v1/generate

Generate a PDF from HTML or a stored template.

Request body

FieldTypeRequiredDescription
htmlstringone ofInline HTML document
templatestringone ofTemplate id or slug
dataobjectnoData passed to the template
optionsobjectnoPDF rendering options
asyncbooleannoIf true, enqueue and return 202
webhook_urlstringnoURL to POST on completion (async)

Options

OptionTypeDefault
formatA4 | A3 | A5 | Letter | Legal | TabloidA4
landscapebooleanfalse
margin{ top, bottom, left, right }20/20/15/15 mm
header_htmlstring
footer_htmlstring
print_backgroundbooleantrue
scalenumber1
page_rangesstringall

Response (sync, 200)

jsonexample
{
  "id": "pdf_abc123",
  "status": "completed",
  "url": "https://files.pdfend.com/pdf_abc123.pdf",
  "pages": 3,
  "size": 45230,
  "duration_ms": 1180
}

Response (async, 202)

jsonexample
{
  "id": "pdf_abc123",
  "status": "queued",
  "poll_url": "https://api.pdfend.com/v1/generations/pdf_abc123"
}

Errors

jsonexample
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "html or template is required"
  },
  "request_id": "req_01HX..."
}

cURL

bashexample
curl -X POST https://api.pdfend.com/v1/generate \
  -H "Authorization: Bearer pk_live_..." \
  -H "Content-Type: application/json" \
  -d '{"html":"<h1>Hello</h1>","options":{"format":"A4"}}'