Skip to main content

Page Setup

The pageSetup object controls the physical layout of every page in your PDF. All properties are optional and fall back to sensible defaults when omitted.

Properties

PropertyTypeDefaultDescription
sizestring | array"A4"Named page size, or a custom [width, height] — unit strings ("4in", "152mm", "10cm", "288pt") or bare numbers in points
orientationstring"portrait"Page orientation
marginsarray[36, 36, 36, 36][top, right, bottom, left] — numbers in points or unit strings ("0.5in", "12.7mm")
backgroundColorstring | string[]Page background. Single hex string for one color, array for per-page banding (cycles when fewer entries than pages).
borderTopstringTop page border — CSS shorthand "<width> <style> <color>" (e.g. "1pt solid #000", "none").
borderRightstringRight page border (CSS shorthand).
borderBottomstringBottom page border (CSS shorthand).
borderLeftstringLeft page border (CSS shorthand).

Page sizes

DocPayload supports all standard ISO and North American page sizes:

ISO A series

SizeDimensions (mm)
A0841 x 1189
A1594 x 841
A2420 x 594
A3297 x 420
A4210 x 297
A5148 x 210
A6105 x 148
A774 x 105
A852 x 74
A937 x 52
A1026 x 37

ISO B series

SizeDimensions (mm)
B1707 x 1000
B2500 x 707
B3353 x 500
B4250 x 353
B5176 x 250
B6125 x 176
B788 x 125
B862 x 88
B944 x 62
B1031 x 44

North American sizes

SizeDimensions (in)
LETTER8.5 x 11
LEGAL8.5 x 14
TABLOID11 x 17
LEDGER17 x 11
EXECUTIVE7.25 x 10.5

Label & tag formats

Standard thermal-label stock sizes, named width-first the way the stock is sold:

SizeDimensions (in)Typical use
LABEL-4X64 x 6Shipping label, pallet plate
LABEL-4X44 x 4Carton label
LABEL-4X24 x 2Address label
LABEL-3X23 x 2Bin / product tag
LABEL-2X12 x 1Barcode sticker
{
"document": {
"pageSetup": {
"size": "LABEL-4X6",
"margins": [12, 12, 12, 12]
},
"content": [
{ "p": "4 × 6 inch thermal shipping label." }
]
}
}

Omit size to fall back to the engine default (A4).

Custom page sizes

When no named size fits — tickets, badges, wide receipts, oversized placards — set size to a two-element [width, height] array. Each dimension is a unit string in the measure you already think in — "in", "mm", "cm", or "pt":

{
"document": {
"pageSetup": {
"size": ["3.5in", "5.5in"],
"margins": [12, 12, 12, 12]
},
"content": [
{ "p": "3.5 × 5.5 inch event badge." }
]
}
}

["90mm", "140mm"] and ["9cm", "14cm"] work the same way. A bare number is read as points (1 point = 1/72 inch, so 72 pt = 1 inch = 25.4 mm) — the unit the rest of the document model (margins, font sizes) uses.

Each dimension must be between 0.25 and 200 inches (18 to 14,400 points). orientation applies to custom sizes the same way it does to named ones — landscape swaps the two dimensions. Custom sizes work at the document root and in per-section overrides alike.

note

Microsoft Word caps page dimensions at 22 inches (1,584 points). Larger custom pages render fine in PDF, but open oversized in Word from DOCX output.

Orientation

ValueDescription
portraitTaller than wide (default)
landscapeWider than tall

When landscape is set, the page dimensions are swapped. For example, A4 landscape produces a 297 x 210 mm page.

Margins

Margins are a four-element array:

[top, right, bottom, left]

Each entry is a bare number in points (1 point = 1/72 inch) or a unit string in "in", "mm", "cm", or "pt" — mix freely:

"margins": ["0.75in", "12.7mm", "0.75in", "12.7mm"]

For reference:

  • 72 points = 1 inch = 25.4 mm
  • 50 points is approximately 17.6 mm or 0.69 inches

Examples

A4 portrait with default margins

{
"document": {
"pageSetup": {
"size": "A4",
"orientation": "portrait",
"margins": [50, 40, 50, 40]
},
"content": [
{ "p": "Standard A4 document." }
]
}
}

US Letter landscape with wide margins

{
"document": {
"pageSetup": {
"size": "LETTER",
"orientation": "landscape",
"margins": [72, 72, 72, 72]
},
"content": [
{ "p": "Landscape letter with 1-inch margins on all sides." }
]
}
}
{
"document": {
"pageSetup": {
"size": "LEGAL",
"orientation": "portrait",
"margins": [60, 30, 60, 30]
},
"content": [
{ "p": "Legal-size document with narrow side margins for maximum content width." }
]
}
}

Tabloid for large-format reports

{
"document": {
"pageSetup": {
"size": "TABLOID",
"orientation": "portrait",
"margins": [50, 50, 50, 50]
},
"content": [
{ "p": "Tabloid-size document for large charts and diagrams." }
]
}
}

Page background colors

Apply different background colors to successive pages. Colors cycle if there are more pages than entries.

{
"document": {
"pageSetup": {
"size": "A4",
"margins": [
50,
40,
50,
40
],
"backgroundColor": [
"#FAFAFA",
"#F0F4FF"
]
},
"content": [
{
"p": "Page 1 has a light gray background."
},
{
"break": "page"
},
{
"p": "Page 2 has a light blue background."
},
{
"break": "page"
},
{
"p": "Page 3 cycles back to light gray."
}
]
}
}
note

backgroundColor currently renders on top of content in some configurations. Use light, subtle colors and test your output to ensure readability.

Page borders

Add border rules to every page. Each side is its own property — borderTop, borderRight, borderBottom, borderLeft — using the CSS shorthand "<width> <style> <color>". Components are independently optional and can appear in any order; "none" removes the side. Sides are independent: setting borderTop doesn't reset the others.

{
"document": {
"pageSetup": {
"size": "A4",
"margins": [50, 40, 50, 40],
"borderTop": "0.5pt solid #CCCCCC",
"borderBottom": "0.5pt solid #CCCCCC"
},
"content": [
{ "p": "This document has thin gray rules at the top and bottom of every page." }
]
}
}

Combine all four sides for a full page frame:

"pageSetup": {
"borderTop": "1pt solid #1A1A2E",
"borderRight": "1pt solid #1A1A2E",
"borderBottom": "1pt solid #1A1A2E",
"borderLeft": "1pt solid #1A1A2E"
}

Per-section overrides

The pageSetup at the document root is the default for every page. To change page setup partway through — a landscape appendix, a different page size for an insert, narrower margins for a chapter — partition the document with a section break that carries its own inline pageSetup.

{
"document": {
"pageSetup": {
"size": "LETTER",
"orientation": "portrait",
"margins": [50, 50, 50, 50]
},
"content": [
{ "h1": "Main body" },
{ "p": "Renders with the document-root pageSetup (LETTER portrait)." },

{ "break": "section",
"pageSetup": {
"size": "TABLOID",
"orientation": "landscape",
"margins": [30, 30, 30, 30],
"backgroundColor": "#FAFAFA"
}
},

{ "h1": "Appendix" },
{ "p": "Renders TABLOID landscape with the appendix pageSetup applied to every page in this section." }
]
}
}

The inline pageSetup on the break accepts every key the document-root pageSetup does — size, orientation, margins, backgroundColor, borderTop/borderRight/borderBottom/borderLeft. Each property is independent: omit a key to inherit it from the document root. The break also accepts inline header / footer for per-section chrome (see Headers & Footers).

pageSetup is for page-level configuration only — it does not accept content-formatting keys like fontSize or color. Those belong in styles and apply to text elements, not pages.

A section break starts a new page when the resolved page setup differs from the previous section's. Sections sharing identical setup may render on the same physical page.