Headers and page numbers
Edit shared headers and footers, select section variants, and insert page fields.
Headers and footers
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();| Target | Behavior |
|---|---|
| section | Zero-based index; creates or updates the section reference |
| type | default, first, or even variant |
| Part name | Edits 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.
| API | Result |
|---|---|
| updateStory | Returns a child NativeWordDocument with region-local positions |
| removeStory | Removes the native override and restores source behavior; retains the original package part |
| wordStoryArtifact | Opens an existing story for package editing |
| createWordStory | Creates 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.