Page Setup
The pageSetup object controls the physical layout of every page, in the PDF and in the DOCX. All properties are optional and fall back to sensible defaults when omitted.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
size | string | array | "A4" | Named page size, "WxH" in points ("288x432"), or a custom [width, height] — unit strings ("4in", "152mm", "288pt", "400px") or bare numbers in points |
orientation | string | — | Turns a named size; absent, the size stands as its name defines it |
margin | number | string | array | [36, 36, 36, 36] | One number of points for all four sides, a string of one to four lengths in CSS order ("20mm", "10mm 20mm"), or [top, right, bottom, left] — numbers in points or unit strings ("0.5in", "12.7mm") |
marginTop, marginRight, marginBottom, marginLeft | number | string | — | One side alone, over margin; a section that states one keeps the other three |
gutter | number | string | 0 | Extra margin on the binding edge, so bound text clears the spine |
mirrorMargins | boolean | false | Swaps left and right margins on every second page, as the facing pages of a book |
backgroundColor | string | string[] | — | Colour over the whole page, under everything on it. An array gives each page the next colour in turn, starting again after the last. |
backgroundImage | string | — | url(name.png): an image over the whole paper, under everything else; none switches the document's off for a section |
backgroundSize | string | its own size | cover, contain, or a width and height, each auto, a length or a percentage ("50% auto") |
backgroundPosition | string | top-left | Where the first copy stands: one to four of left, center, right, top, bottom, a length or a percentage |
backgroundRepeat | string | repeat | repeatX, repeatY, or one or two of repeat, space, round, noRepeat |
border | string | — | All four sides of a frame around the page, "<width> <style> <color>" |
borderWidth, borderStyle, borderColor | string | — | One part of the frame's four sides |
borderTop | string | — | Top page border — CSS shorthand "<width> <style> <color>" (e.g. "1pt solid #000", "none"). |
borderRight | string | — | Right page border (CSS shorthand). |
borderBottom | string | — | Bottom page border (CSS shorthand). |
borderLeft | string | — | Left page border (CSS shorthand). |
pageNumbering | object | — | { "start": 1, "format": "lowerRoman" }: where the count starts and in what style; see Page numbering |
Page sizes
DocPayload supports all standard ISO and North American page sizes:
ISO A series
| Size | Dimensions (mm) |
|---|---|
A0 | 841 x 1189 |
A1 | 594 x 841 |
A2 | 420 x 594 |
A3 | 297 x 420 |
A4 | 210 x 297 |
A5 | 148 x 210 |
A6 | 105 x 148 |
A7 | 74 x 105 |
A8 | 52 x 74 |
A9 | 37 x 52 |
A10 | 26 x 37 |
ISO B series
| Size | Dimensions (mm) |
|---|---|
B1 | 707 x 1000 |
B2 | 500 x 707 |
B3 | 353 x 500 |
B4 | 250 x 353 |
B5 | 176 x 250 |
B6 | 125 x 176 |
B7 | 88 x 125 |
B8 | 62 x 88 |
B9 | 44 x 62 |
B10 | 31 x 44 |
North American sizes
| Size | Dimensions (in) |
|---|---|
LETTER | 8.5 x 11 |
LEGAL | 8.5 x 14 |
TABLOID | 11 x 17 |
LEDGER | 11 x 17 (the tabloid sheet; landscape lays it across) |
EXECUTIVE | 7.25 x 10.5 |
Screen format
| Size | Dimensions (pt) | Typical use |
|---|---|---|
SOCIAL | 630 x 1200 | A share card in the 1.91:1 ratio; "orientation": "landscape" gives the usual 1200 x 630 |
Label & tag formats
Standard thermal-label stock sizes, named width-first the way the stock is sold:
| Size | Dimensions (in) | Typical use |
|---|---|---|
LABEL-4X6 | 4 x 6 | Shipping label, pallet plate |
LABEL-4X4 | 4 x 4 | Carton label |
LABEL-4X2 | 4 x 2 | Address label |
LABEL-3X2 | 3 x 2 | Bin / product tag |
LABEL-2X1 | 2 x 1 | Barcode sticker |
{
"document": {
"pageSetup": {
"size": "LABEL-4X6",
"margin": [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", "pt", or "px":
{
"document": {
"pageSetup": {
"size": ["3.5in", "5.5in"],
"margin": [12, 12, 12, 12]
},
"content": [
{ "p": "3.5 × 5.5 inch event badge." }
]
}
}
["90mm", "140mm"] and ["3.5in", "5.5in"] 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.
A size can also be one string, "WxH" in points: "size": "288x432" is a 4 x 6 inch page.
Each dimension must be between 0.25 and 200 inches (18 to 14,400 points). A custom size stands as written: orientation turns a named size only, and beside a custom one it is reported and ignored, so write the width and height in the order you want them. Custom sizes work at the document root and in per-section overrides alike.
Microsoft Word caps page dimensions at 22 inches (1,584 points). Larger custom pages render fine in PDF; the DOCX writes such a page held to 22 inches and reports it.
Orientation
| Value | Description |
|---|---|
portrait | Taller than wide: the short side across |
landscape | Wider than tall: the long side across |
Without orientation, a named size stands as its name defines it: A4 is portrait, while LABEL-4X2 (4 x 2 in) is wider than tall. Setting landscape puts the long side across, so A4 landscape produces a 297 x 210 mm page.
Margins
Margins take three forms: one number of points for all four sides ("margin": 36), a string of one to four lengths in CSS order ("margin": "20mm", "margin": "10mm 20mm"), or a four-element array:
[top, right, bottom, left]
Each array entry is a bare number in points (1 point = 1/72 inch) or a unit string in "in", "mm", "pt", or "px" — mix freely:
"margin": ["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
marginTop, marginRight, marginBottom and marginLeft set one side alone, over margin, as CSS's longhands do. In a section they change that side only and the other three stay the document's:
{
"document": {
"pageSetup": { "size": "A5", "margin": "20mm" },
"content": [
{ "p": "Equal 20 mm margins." },
{ "break": "section", "pageSetup": { "marginLeft": "40mm" } },
{ "p": "The same page with a deep left margin." }
]
}
}
Facing pages: gutter and mirror margins
For a bound document, gutter adds margin on the binding edge so the text clears the spine, and mirrorMargins swaps the left and right margins on every second page, as the facing pages of a book. With mirrorMargins, margin describes the first page and the gutter stays on the inner edge of every page; without it, the gutter sits on the first page's binding side. To put the page number on the outer edge too, give the footer left and right.
{
"document": {
"pageSetup": {
"size": "A5",
"margin": [36, 36, 36, 42],
"gutter": "28pt",
"mirrorMargins": true
},
"content": [
{ "p": "Page 1: the 28pt gutter and the 42pt margin stand on the left, the binding side." },
{ "break": "page" },
{ "p": "Page 2: they stand on the right." }
]
}
}
When the body style sets "direction": "rtl", or sets its lines vertical with "writingMode": "verticalRl" as a Japanese or Chinese book does, pages progress right to left: the first page is a left page, bound on its right edge, and every page mirrors that way. A verticalLr body progresses left to right, whatever its direction.
Examples
A4 portrait with default margins
{
"document": {
"pageSetup": {
"size": "A4",
"orientation": "portrait",
"margin": [50, 40, 50, 40]
},
"content": [
{ "p": "Standard A4 document." }
]
}
}
US Letter landscape with wide margins
{
"document": {
"pageSetup": {
"size": "LETTER",
"orientation": "landscape",
"margin": [72, 72, 72, 72]
},
"content": [
{ "p": "Landscape letter with 1-inch margins on all sides." }
]
}
}
Legal portrait with narrow side margins
{
"document": {
"pageSetup": {
"size": "LEGAL",
"orientation": "portrait",
"margin": [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",
"margin": [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",
"margin": [
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."
}
]
}
}
Page background image
backgroundImage lays an image over the whole paper, under the frame and the content: url(name.png), looked up like any image the document names. backgroundSize, backgroundPosition and backgroundRepeat take CSS's values and are measured against the page area (the text area inside the margins and the gutter), as CSS Paged Media places a page background; copies that repeat run on from it over the margins to the paper's edges. Without the three keys, the image tiles at its own size from the page area's top-left corner.
| Key | Values |
|---|---|
backgroundSize | cover, contain, or one or two of auto, a length or a percentage ("50% auto", "auto 300pt", "100% 100%") |
backgroundPosition | one to four of left, center, right, top, bottom, a length or a percentage ("center", "right bottom", "20% 80%", "right 20pt bottom 30pt") |
backgroundRepeat | repeat (default), repeatX, repeatY, noRepeat, space (spread to the edges), round (rescaled to fit whole), or two of them for across and down ("space round") |
{
"document": {
"pageSetup": {
"size": "A5",
"margin": [90, 50, 40, 50],
"backgroundImage": "url(images/paper-grid.png)",
"backgroundSize": "contain",
"backgroundPosition": "center",
"backgroundRepeat": "noRepeat"
},
"content": [
{ "p": "One copy of the grid, as large as fits the page area, centred in it." }
]
}
}
A page that mirrors or has a gutter positions the image in its own page area, so the pattern moves with the text from a right page to a left one. "backgroundImage": "none" on a section switches the document's image off for that section.
Page frame
border draws all four sides of a frame around the page, as "<width> <style> <color>". The parts follow a box's border: border first, then borderWidth, borderStyle and borderColor, each changing one part of all four sides, then a side's own borderTop, borderRight, borderBottom or borderLeft, the most specific. A width alone draws a solid black frame of that width; a style or a colour alone draws one half a point wide. The frame stands at the paper's edge and does not move the text.
{
"document": {
"pageSetup": {
"size": "A5",
"border": "0.5pt solid #1f4e79"
},
"content": [
{ "p": "A half-point blue frame." },
{ "break": "section", "pageSetup": { "borderWidth": "3pt", "borderStyle": "double" } },
{ "p": "The same blue, three points wide and double." },
{ "break": "section", "pageSetup": { "borderTop": "12pt solid #c62828", "borderBottom": "none" } },
{ "p": "A heavy red top, the document's frame on the sides, and no bottom." }
]
}
}
borderStyle takes solid, dashed, dashedFixed, dotted, roundDots, double, groove, ridge, inset, outset and none. A section that writes only one part keeps the document's other parts, and "none" (or a width of 0) turns a side, or the frame, off.
Each side can still be written on its own:
{
"document": {
"pageSetup": {
"size": "A4",
"margin": [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." }
]
}
}
Page numbering
pageNumbering sets how a section's pages are numbered: start, the number its first page carries (1 or more), and format, the counter style (default decimal). $global.PAGE in a header, footer or watermark prints the result, and the PDF's page labels say the same number, so a reader's page box agrees with the printed folio.
{
"document": {
"pageSetup": { "pageNumbering": { "start": 1, "format": "lowerRoman" } },
"footer": { "content": [ { "p": "$global.PAGE", "style": "folio" } ] },
"styles": { "folio": { "textAlign": "center", "fontSize": 9 } },
"content": [
{ "h1": "Preface" },
{ "p": "Numbered i, ii, ..." },
{ "break": "section", "pageSetup": { "pageNumbering": { "start": 1 } } },
{ "h1": "Chapter 1" },
{ "p": "Numbered 1, 2, ... again." }
]
}
}
Absent, a section's count carries on from the section before, in the style it had. A format with no start changes the style and carries the count on; a start with no format restarts in decimal.
format | Prints |
|---|---|
decimal, decimalLeadingZero | 1, 2, 3 / 01, 02, 03 |
lowerRoman, upperRoman | i, ii, iii / I, II, III |
lowerAlpha (= lowerLatin), upperAlpha (= upperLatin) | a ... z, aa, ab / A ... Z, AA, AB |
lowerGreek, upperGreek | α, β, γ / Α, Β, Γ |
hebrew, armenian, lowerArmenian, upperArmenian | the script's letter numbering |
arabicIndic, persian, devanagari, bengali, gujarati, gurmukhi, kannada, malayalam, oriya, tamil, telugu, thai, lao, khmer (= cambodian), myanmar, mongolian, tibetan | the script's own digits |
disc, circle, square | the one symbol on every page |
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",
"margin": [50, 50, 50, 50]
},
"content": [
{ "h1": "Main body" },
{ "p": "Renders with the document-root pageSetup (LETTER portrait)." },
{ "break": "section",
"pageSetup": {
"size": "TABLOID",
"orientation": "landscape",
"margin": [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. Each key is independent: one the section omits is the document root's, never the previous section's, so a bare { "break": "section" } returns to the root's page. pageNumbering is the exception: absent, the count and its style carry on from the section before. The break also takes watermarks in place of the document's (absent, the document's; [], none) and a header or footer, which applies from that section on (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 always starts a new page, even when its setup matches the previous section's. A section break at the very start of the content makes no blank page: page 1 takes its setup.
In a DOCX
gutterandmirrorMarginsare written as Word's own gutter and mirrored margins; a right-to-left document's section binds on the right.- The page frame is Word's page border, drawn at the paper's edge as in the PDF. Word holds a border to 12pt, and a wider one is reported.
backgroundColoris one colour per section, painted behind the text. A list that alternates colours page by page cannot be carried, and is reported.backgroundImageis carried, each copy placed in the page area, so mirrored pages and the gutter move it as in the PDF; past 1,024 copies a section, the rest are reported, and a largerbackgroundSizeis the lever.pageNumberingis Word's page numbering.decimal,lowerRoman,upperRoman,hebrew,devanagari,thaianddiscare written as they are;circleandsquareprint Word's one bullet; every other style is numbered in decimal, the same numbers in other digits, and a notice says so.- A page wider or taller than 22 inches (1,584 points) is held to 22 inches, and reported (see Custom page sizes).