Page properties (converters)
Passproperties to convert() to control the generated PDF:
| Property | Type | Description |
|---|---|---|
singlePage | boolean | Render entire content on one page (default: false) |
size | { width, height } | Paper size. Numbers = inches; strings support pt, px, in, mm, cm, pc (e.g. "210mm", "297mm" for A4) |
margins | { top, bottom, left, right } | Margins; same unit rules as size |
preferCssPageSize | boolean | Use CSS page size when set (default: false) |
printBackground | boolean | Include background graphics (default: false) |
omitBackground | boolean | Transparent background (default: false) |
landscape | boolean | Landscape orientation (default: false) |
scale | number | Page scale (default: 1.0) |
nativePageRanges | { from, to } | Page range to print |
Standard paper sizes
Common sizes (width × height) you can use inproperties.size:
| Format | Dimensions (in) | Example size |
|---|---|---|
| A6 | 4.13 × 5.83 | { width: 4.13, height: 5.83 } |
| A5 | 5.83 × 8.27 | { width: 5.83, height: 8.27 } |
| A4 | 8.27 × 11.7 | { width: "210mm", height: "297mm" } |
| Letter | 8.5 × 11 (default) | { width: 8.5, height: 11 } |
| Legal | 8.5 × 14 | { width: 8.5, height: 14 } |
| A3 | 11.7 × 16.54 | { width: "297mm", height: "420mm" } |
Single page
WhensinglePage is true, Chromium fits the entire content on one long page and overrides paper height and native page ranges.
Print media
Chromium uses print media by default. The PDF can look different from the browser (e.g. backgrounds omitted). UseprintBackground: true to include background graphics, or set emulatedMediaType: "screen" (in conversion options) to use screen media. You can target print in CSS with @media print; use preferCssPageSize: true so Chromium respects @page size and margins.
Background logic
The resulting background depends onprintBackground, omitBackground, and whether your document has a background:
printBackground | omitBackground | Document has background? | Result |
|---|---|---|---|
false | any | any | No background |
true | any | Yes | Uses HTML/CSS background |
true | true | No | Transparent |
true | false | No | White (default) |
Rendering and wait
Chromium captures the current DOM. If the page uses JavaScript to render content (e.g. SPAs, charts), use wait options so conversion runs when content is ready. PreferwaitForExpression or waitForSelector over waitDelay: they are more reliable. Use waitDelay only as a fallback when you cannot change the page; it is less reliable if load time varies.
Conversion options (converters)
In addition toproperties, convert() accepts:
- Wait:
waitDelay(e.g."5s"),waitForSelector,waitForExpression— see Rendering and wait - Header/footer:
header,footer— path,Buffer, orReadStream(see below) - HTTP:
extraHttpHeaders,cookies,failOnHttpStatusCodes,failOnResourceHttpStatusCodes,ignoreResourceHttpStatusDomains,failOnResourceLoadingFailed,skipNetworkIdleEvent(see below) - Behavior:
failOnConsoleExceptions,failOnResourceLoadingFailed,skipNetworkIdleEvent - PDF:
pdfUA(accessibility),metadata,userPassword,ownerPassword,embeds - Split:
split—{ mode: "pages" | "intervals", span, unify?, flatten? }
Header and footer
Headers and footers are rendered in an isolated context: your main page’s CSS does not apply, JavaScript does not run, and external requests (images, fonts) are not allowed. Provide complete HTML documents. Chromium injects dynamic values into elements with these class names:pageNumber, totalPages, date, title, url. Use base64-encoded images inline (e.g. <img src="data:image/png;base64,...">). Add -webkit-print-color-adjust: exact; in your header/footer CSS if you need background or text colors to print.
HTTP and networking
extraHttpHeaders— Object of header name → value; sent with every request (main page and resources). You can scope a header to certain URLs by appending;scope=<regex>to the value (the token is stripped before sending).cookies— Array of{ name, value, domain }(and optionalpath,secure,httpOnly,sameSite) for authentication or session state.failOnHttpStatusCodes— Array of status codes (or ranges via X99 notation, e.g.499= 400–499). If the main page returns a matching code, Gotenberg returns 409 Conflict. Default is[499, 599].failOnResourceHttpStatusCodes— Same for subresources (images, CSS, scripts). UseignoreResourceHttpStatusDomainsto exclude hostnames from this check (e.g. analytics).failOnResourceLoadingFailed— Iftrue, conversion fails with 400 when any resource fails to load (e.g. 404 image); by default the PDF is still generated with missing assets.skipNetworkIdleEvent— Iftrue, Chromium does not wait for the network to be idle before converting (defaultfalse).
Screenshot options (capture)
Passproperties to capture() for image output:
| Property | Type | Description |
|---|---|---|
format | "png" | "jpeg" | "webp" | Image format |
quality | number (0–100) | JPEG compression quality |
omitBackground | boolean | Transparent background |
width | number | Viewport width in pixels (default: 800) |
height | number | Viewport height in pixels (default: 600) |
clip | boolean | Clip to viewport (default: false) |
capture() options mirror the conversion options where applicable (e.g. waitDelay, waitForSelector, extraHttpHeaders, optimizeForSpeed). See Reference — screenshots.