Skip to main content
extractDocx lays out the document once and gives you blocks: headings, paragraphs, list items, tables and figures. Each block has its page, its box and its text.
The CLI writes the same JSON: npx docx blocks input.docx -o blocks.json.

Find the page of a citation

A citation that points into the text as (bodyIndex, textOffset) needs spanOffsets. Each span of a body paragraph then has textOffset and textLength: where its text is in the paragraph.
The offsets count the paragraph’s text in the final view. This is the same text that Paragraph.text gives in the Office.js API, and that an editor Position counts:
  • Deleted text takes no room. A deleted span has textLength: 0.
  • A list number is not paragraph text. A marker span has no offsets.
  • A span’s text can be longer or shorter than its range. A tab paints as spaces, and "\n" between two lines stands for the space where the line wraps.
  • The space where a paragraph goes onto the next page is in neither block.
A table cell, a header, a footer and a text box have no offsets yet.

Same pages in Node and in the browser

extractDocx, docx pdf and the editor use one layout engine. With the same bytes, the same fonts and the same view, they break the pages at the same places: “The same fonts” means the same font files. Give the server the faces that the browser loads: the portable fonts, or one font mirror for both (see Fonts). If a font is missing on one side, its metrics change and the line breaks can move.