PDFCraft

Option reference

Generated from the same specification the API validates against, so this table and the accepted options cannot drift apart. Anything not listed here is a 400 invalid_request.

Request body

FieldTypeDefaultNotes
htmlstring, ≤5000000 charsThe document to render. Mutually exclusive with url; exactly one is required.
urlstring, ≤2000 charsA public http(s) URL to render. Mutually exclusive with html.
outputbinary | urlbinary"binary" streams application/pdf back; "url" uploads and returns a signed link.
filenamestring, ≤255 charsdocument.pdfUsed for Content-Disposition on binary output and in the signed URL.
headersobjecturl input only. Extra request headers, e.g. an Authorization header.
cookiesobjecturl input only. Array of {name, value, domain?, path?} seeded into the context.

Exactly one of html or url. Both, or neither, is a 400.

options

OptionTypeDefaultNotes
formatA4 | A3 | A5 | Letter | Legal | TabloidA4Paper size. Ignored if the page CSS declares its own @page size.
landscapebooleanfalseRotate the paper to landscape orientation.
marginobjectPage margins. Any side may be omitted; omitted sides default to 0.
margin.topCSS length, e.g. "20mm"e.g. "20mm", "1in", "72px".
margin.rightCSS length, e.g. "20mm"e.g. "15mm".
margin.bottomCSS length, e.g. "20mm"e.g. "20mm".
margin.leftCSS length, e.g. "20mm"e.g. "15mm".
scalenumber 0.1–21Rendering scale factor.
printBackgroundbooleantruePrint background colours and images. Off by default in browsers; on by default here.
pageRangesstring, /^[0-9,\-\s]+$/Subset of pages to keep, e.g. "1-5" or "1,4,7-9". Empty means all pages.
headerHtmlstring, ≤50000 charsHTML for the running header. Supports Chromium print classes: date, title, url, pageNumber, totalPages. Needs a top margin to be visible.
footerHtmlstring, ≤50000 charsHTML for the running footer. Same classes as headerHtml; needs a bottom margin.
waitForobjectConditions to satisfy before the PDF is taken. All of them apply, in order.
waitFor.selectorstring, ≤500 charsWait until this CSS selector is attached to the DOM.
waitFor.networkIdlebooleanfalseWait until there have been no network connections for 500 ms.
waitFor.delayMsinteger 0–300000Fixed pause after the other wait conditions are satisfied.
emulateMediaprint | screenprintWhich CSS media type the page sees.
timeoutMsinteger 1000–12000030000Hard ceiling on the whole render. Exceeding it returns 408 render_timeout.

Headers

HeaderDirectionNotes
AuthorizationrequestBearer sk_live_…. Required on every /v1 endpoint.
Idempotency-KeyrequestSame key and same body within 24 hours returns the original render instead of rendering — and billing — again.
X-Renders-RemainingresponseOn every successful render.
Retry-AfterresponseSeconds to wait, on 429 rate_limited.
X-SignaturecallbackHMAC-SHA256 of the raw callback body, keyed with your webhook secret.

Header and footer templates

headerHtml and footerHtml are rendered by Chromium in a separate document from the page. Two things trip people up: they inherit no page CSS, so set font-size inline, and they are invisible unless the matching margin leaves room for them. These classes are substituted: date, title, url, pageNumber, totalPages.

"headerHtml": "<div style='font-size:9px;width:100%;text-align:center'>Acme Ltd</div>",
"footerHtml": "<div style='font-size:9px;width:100%;text-align:right;padding-right:15mm'><span class='pageNumber'></span> / <span class='totalPages'></span></div>",
"margin": { "top": "20mm", "bottom": "20mm" }