Headers and page numbers

Edit shared headers and footers, select section variants, and insert page fields.

Headers and footers

TypeScript
import { NativeWordDocument, openWordArtifact, wordPageNumberRuns } from '@tumblerjs/word';

const source = openWordArtifact(bytes);
const model = new NativeWordDocument({ source });
const footer = model.updateStory({ section: 0, kind: 'footer', type: 'default' }, [{
  kind: 'paragraph', alignment: 'end',
  runs: wordPageNumberRuns('page-x-of-y'),
}]);
const positions = footer.paragraphs();
const edited = model.artifact().bytes();
TargetBehavior
sectionZero-based index; creates or updates the section reference
typedefault, first, or even variant
Part nameEdits the shared story for every section that references or inherits it

Resolve part names from source.document.headerFooters. Do not assume a filename such as /word/header1.xml.

APIResult
updateStoryReturns a child NativeWordDocument with region-local positions
removeStoryRemoves the native override and restores source behavior; retains the original package part
wordStoryArtifactOpens an existing story for package editing
createWordStoryCreates a package-backed story and returns its part name

Layout pages expose headerStory and footerStory, including the effective section and variant. First/even variants follow document settings.

Layout reserves body space for repeated stories. storyOverflow reports when a story consumes that space; body layout then falls back to section margins.

Live page fields

wordPageNumberRuns supports plain, page, x-of-y, bold-x-of-y, and page-x-of-y. PAGE and NUMPAGES each occupy one U+FFFC character with a field property. Header/footer layout resolves them before measurement and repeats pagination when the total changes.

Supported simple fields and complete complex PAGE/NUMPAGES fields split across runs import as editable fields. Export writes standard Word fields. Section numbering restarts and numeral formats are not evaluated. General fields such as TOC, REF, and SEQ are not recalculated.

Next Collaboration