PDFCraft
Render option

Wait for a chart or font to finish before capturing a PDF

Conditions to satisfy before the PDF is taken. All of them apply, in order.

Fieldoptions.waitFor
Typeobject: selector, networkIdle, delayMs
Defaultnone

Fields

FieldTypeWhat it does
selectorstring, up to 500 charactersWait until this CSS selector is attached to the DOM.
networkIdletrue | falseWait until there have been no network connections for 500 ms.
delayMsinteger, 0 to 30000Fixed pause after the other wait conditions are satisfied.

What it is for

Conditions to satisfy before the PDF is taken — a CSS selector, network idle, a fixed delay. All of them apply, in that order.

The trap

networkIdle never settles on a page with a long-poll, a websocket or an analytics beacon, and the render dies at timeoutMs instead. Prefer selector: have your chart library set a data attribute when it has drawn, and wait for that. It is faster and it cannot hang.

Example

curl -X POST https://api.pdfcraft.dev/v1/render \
  -H "Authorization: Bearer $PDFCRAFT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>hello</h1>",
    "options": {
      "waitFor": {
        "selector": "#chart-ready",
        "networkIdle": false,
        "delayMs": 0
      }
    }
  }' \
  --output out.pdf

Every option

Try any of these in the playground without writing a line of code, or read the full reference.