docx
    Preparing search index...

    Variable estimatePageNumbersConst

    Works out the page each bookmark of a document starts on, and how many pages the document and each of its sections have, by laying out its pages as Word does, so the page numbers of its tables of contents and page references, and its numbers of pages, are written with it. Give it to a document as its pageNumbers, or to patchDocument as its pageNumbers to write a template's once it is patched:

    new Document({ pageNumbers: estimatePageNumbers, sections: [...] });
    await patchDocument({ outputType: "nodebuffer", data, patches, pageNumbers: estimatePageNumbers });

    The pages are laid out with the widths and heights of the fonts Word documents use most, such as Calibri, Cambria, Arial and Times New Roman. To measure text in other fonts, such as Aptos, from their files, use estimatePageNumbersWith. It follows paragraphs' spacing, indents, line spacing, tab stops and keep settings, widow and orphan control, lists, pictures in the line, tables, whose rows break across pages, footnotes and endnotes, page, column and section breaks, and each section's page size, margins, columns, headers, footers and page numbering.

    It stops at the first thing it can't lay out yet: a drawing or table that text flows around, a text box or frame, an equation, a footnote that continues on the next page, columns evened out before a continuous section break, a table row kept whole that is taller than a page, or a character whose width in its font isn't known, such as a mathematical symbol in Calibri, which Word draws in Cambria Math. The page references to bookmarks after it are left blank, for Word to fill in when it updates the fields. A document in compatibility mode, which Word lays out as an older version of Word did, isn't laid out at all. When laying the pages out again with the page numbers it worked out still changes them after three passes, as when a table of contents wraps one way with a number and the other way without it, all of them are left blank.

    Page references, tables of contents and SEQ fields (caption numbers, which are counted without laying out the pages) are written clean, so Word shows the numbers as they are written, and the numbers left blank stay blank, without asking to update the fields, unless the document has updateFields on.