Headers & Footers
The header and footer objects define content that repeats on every page of the document. Both support text content with page-number tokens, a visual boundary rule, and the ability to skip specific pages.
Properties
| Property | Type | Description |
|---|---|---|
content | array | Array of content elements (paragraphs with inline formatting, svg, columns, ...) |
hr | object | Horizontal rule separating header/footer from body content. Uses the same hr definition as the content element. |
left | array | What the band draws on left pages, in place of content (see Left and right pages) |
right | array | What the band draws on right pages, in place of content |
skipPages | number[] | Array of 1-based page positions where this header/footer should not appear |
offset | number | The band's outer edge, in points from the page's edge (default 8). The band is the strip between offset and the page margin: a header's content starts at offset from the top edge and runs down; a footer's content starts at the bottom margin line and runs down towards offset, so a footer is moved further from the text with paddingTop on its content's style, and content past the strip is clipped |
Content
The content array works the same as the document's main content array. Each element supports $data resolution and inline formatting tags such as [b], [color], [tab], [image].
{
"header": {
"content": [
{ "p": "ShipForge[tab, 400, 0]Quarterly Report", "style": "headerStyle" }
]
}
}
Page numbers
Page numbering uses the global tokens $global.PAGE and $global.NUMPAGES, resolved at render time inside any header or footer paragraph. See Globals for the full list.
{
"footer": {
"content": [
{ "p": "Page [b]$global.PAGE[/b] of $global.NUMPAGES", "style": "footerStyle" }
]
}
}
Shortcodes work inside the page-number paragraph just like any other content.
$global.PAGE prints the number the page shows, in the style the section's pageSetup.pageNumbering gives (i, ii in a preface, 1 again where the body restarts). $global.NUMPAGES counts every page of the document.
Section numbers and running heads
Two more tokens resolve per page, in a header, a footer or a watermark:
| Token | Prints |
|---|---|
$global.SECTION | The section's number: 1, then one more at each break: "section" |
$global.STYLEREF.<style> | The text of the first block wearing <style> that begins on the page, else of the last one before it: a chapter's title heads every page of the chapter, and a page where two meet is headed by the one it opens with. Blank on the pages before the first such block |
{
"document": {
"header": {
"content": [ { "p": "$global.STYLEREF.h1[tab, 400, 0]Section $global.SECTION" } ]
},
"content": [
{ "h1": "Scope" },
{ "p": "Every page until the next heading is headed Scope." },
{ "break": "section" },
{ "h1": "Terms" },
{ "p": "From here the header reads Terms, section 2." }
]
}
}
The style is the one a block wears: h1 for a heading node, or a named style ($global.STYLEREF.chapter for { "p": "...", "style": "chapter" }). A style no block wears is left as written and reported. In the body, these tokens do not resolve: the body is laid once, and the render report names any it finds there.
Boundary rule
The hr property draws a horizontal rule between the header/footer area and the page body. It accepts the same properties as the standalone hr element.
{
"header": {
"content": [
{ "p": "ShipForge[tab, 400, 0]Quarterly Report", "style": "headerStyle" }
],
"hr": { "borderStyle": "solid", "height": 0.5, "color": "#CCCCCC" }
}
}
Any borderStyle supported by hr works here -- solid, dashed, dotted, double, groove, ridge, inset, outset, dashedFixed, or none.
Skip pages
Use skipPages to suppress a header or footer on specific pages. Page numbers are 1-based positions in the whole document, whatever a section's pageNumbering prints -- commonly used to hide the header on a title page.
{
"header": {
"content": [ { "p": "Quarterly Report" } ],
"skipPages": [1]
}
}
Left and right pages
left and right are what the band draws on left pages and on right pages, in place of content, as CSS's :left and
:right page selectors do. With mirrorMargins this puts the page number on the outer
edge of every page, away from the binding:
{
"document": {
"pageSetup": { "size": "A5", "mirrorMargins": true, "gutter": 14 },
"styles": {
"folioLeft": { "fontSize": 8, "textAlign": "left" },
"folioRight": { "fontSize": 8, "textAlign": "right" }
},
"footer": {
"skipPages": [1],
"left": [{ "p": "$global.PAGE · Assembly and care", "style": "folioLeft" }],
"right": [{ "p": "Assembly and care · $global.PAGE", "style": "folioRight" }]
},
"content": [{ "p": "Step 1: fit the back panel." }]
}
}
| The page | The band draws |
|---|---|
| a left page | left if given, else content |
| a right page | right if given, else content |
- Sides are physical. In a left-to-right document page 1 is a right page, so right pages are the odd-numbered ones and left pages the even ones (Word's "different odd and even pages"). In a right-to-left document page 1 is a left page.
- One side can differ and the other keep
content: givecontentandright, and left pages drawcontent. skipPages,offsetandhrare the band's and apply to both sides.- A band with both sides and
contenttoo never drawscontent, and the render report says so. - A band declared beside a
break: "section"takesleftandrighttoo.
Per-section bands
A header or footer written beside a break: "section" is that section's band, and it stays in force from that section on, until a later section gives another:
| On the section break | The band from this section on |
|---|---|
no header | the band already in force (the document's, or an earlier section's) |
"header": { "content": [...] } | this one, replacing it |
"header": {} | none |
{
"document": {
"header": { "content": [ { "p": "Annual Report" } ] },
"content": [
{ "p": "Cover, under the document's header." },
{ "break": "section", "header": { "content": [ { "p": "Annual Report - Appendices" } ] } },
{ "p": "Appendix A, under the appendix header." },
{ "break": "section", "header": {} },
{ "p": "Back matter, with no header at all." }
]
}
}
The same holds for footer.
A header or footer can also stand as a node of its own in the content, with no break: it takes over from the page
that node lands on, and stays in force until another replaces it. A band so declared inside a list, a table, columns or
another container is not read, and the render report says so: a band opens from the page flow or the document.
{
"document": {
"footer": { "content": [ { "p": "Assembly and care" } ] },
"content": [
{ "p": "Steps 1 to 12." },
{ "h2": "Appendix A: parts list" },
{ "footer": { "content": [ { "p": "Appendix A: parts list" } ] } },
{ "p": "From the page this heading lands on, the footer names the appendix." }
]
}
}
A page a forced break to one side added (see left, right, recto, verso) carries no band at all: it is blank, as a skipped verso is in print.
Bands are page furniture
- A header or footer is laid apart from the page's flow:
floatandcleardo nothing in it, and a notice says so;breakBefore,breakAfter,breakInside,orphansandwidowsdo not break a band either. - Under a PDF/UA claim (see Conformance), headers and footers are marked as page furniture, which a screen reader skips, and are kept out of the document's structure.
Complete example
{
"header": {
"content": [
{ "p": "ShipForge[tab, 400, 0]Quarterly Report", "style": "headerStyle" }
],
"hr": { "borderStyle": "solid", "height": 0.5, "color": "#CCCCCC" },
"skipPages": [1]
},
"footer": {
"content": [
{ "p": "[color, #CC0000]CONFIDENTIAL[/color]", "style": "footerStyle" },
{ "p": "Page [b]$global.PAGE[/b] of $global.NUMPAGES", "style": "footerStyle" }
],
"hr": { "borderStyle": "dashed", "height": 0.4, "color": "#999999" }
}
}
In this example:
- The header sets the company name at the left and the report's title from 400pt via
[tab, 400, 0], a left-aligned stop, is separated from the body by a solid rule, and is hidden on the first page (title page). - The footer shows a red "CONFIDENTIAL" notice, a dashed boundary rule, and a page-number line with
[b]...[/b]bolding around the current page number.
In a DOCX
- Each band is a Word header or footer part, and
$global.PAGE,$global.NUMPAGESand$global.SECTIONare Word fields, which Word computes on each page. $global.STYLEREF.<style>is not carried: the document's styles are not Word styles for Word's running-head field to name. The token is omitted and a warning says so.- Word repeats a band over a whole section and can set only a section's first page apart, so
skipPages: [1]on the document's band is carried and any other skipped page draws the band in the DOCX, with a warning. To leave a band off particular pages in both formats, open abreak: "section"with its ownheaderorfooter. - A band rule's
opacitybelow 1 is not carried, and is reported. - A band with
leftorrightturns on Word's different odd and even pages, which is one setting for the whole document: every section then gets an even-page band, its own side or itscontent. Word takes a page's side from its number, so where a section restarts its count at a number of the other parity, Word puts that page on the other side and may add a blank page; the render report says so.