DOCX

Headers and Footers

Add headers, footers, and page numbers to document sections

Each Section can define its own headers and footers using the headers and footers options.

{
  "sections": [
    {
      "headers": {
        "default": [{ "paragraph": { "alignment": "right", "children": ["My Document"] } }]
      },
      "footers": {
        "default": [
          {
            "paragraph": {
              "alignment": "center",
              "children": ["Page ", "CURRENT", " of ", "TOTAL_PAGES"]
            }
          }
        ]
      },
      "children": [{ "paragraph": { "children": ["Document content goes here."] } }]
    }
  ]
}

Page Number Values

Use these string literals in children arrays to insert dynamic page numbers:

ValueDescription
"CURRENT"Current page number
"TOTAL_PAGES"Total pages in document
"TOTAL_PAGES_IN_SECTION"Total pages in current section
"CURRENT_SECTION"Current section number

First Page and Odd/Even Pages

Use different headers and footers for the first page and alternating pages:

{
  "evenAndOddHeaderAndFooters": true,
  "sections": [
    {
      "properties": {
        "titlePage": true
      },
      "headers": {
        "default": [{ "paragraph": { "children": ["Default Header"] } }],
        "first": [{ "paragraph": { "children": ["First Page Header"] } }],
        "even": [{ "paragraph": { "children": ["Even Page Header"] } }]
      },
      "footers": {
        "default": [{ "paragraph": { "children": ["Default Footer"] } }],
        "first": [{ "paragraph": { "children": ["First Page Footer"] } }],
        "even": [{ "paragraph": { "children": ["Even Page Footer"] } }]
      },
      "children": [{ "paragraph": { "children": ["Content..."] } }]
    }
  ]
}

Options Reference

OptionTypeDescription
childrenSectionChild[]Content elements (paragraphs, tables, etc.)

Section Header/Footer Keys

KeyTypeDescription
defaultSectionChild[]Header/footer for default (odd) pages
firstSectionChild[]Header/footer for first page (requires titlePage)
evenSectionChild[]Header/footer for even pages (requires evenAndOddHeaderAndFooters)
Copyright © 2026