Skip to content

fix(docx): name the blank page Word adds before a section - #920

Merged
DemchaAV merged 1 commit into
2.5-devfrom
fix/docx-blank-page-before-section
Oct 19, 2026
Merged

DemchaAV merged 1 commit into
2.5-devfrom
fix/docx-blank-page-before-section

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

The DOCX export writes every section of a multi-section document with its pages numbered from 1
(w:pgNumType w:start="1"), as the page numbers them. It states different even and odd pages for
the whole document (w:evenAndOddHeaders) once any section has a page zone on even or odd pages
only. With both, Word starts every section on an odd page, so it adds a blank page before a section
whose section before it runs to an odd number of pages. The report said nothing.

Measured in Word 16 and LibreOffice on Windows, with a zone on even pages in one section:

Sections' pages Page Word LibreOffice
1, 1, 1 3 5 (a blank before 2 and 3) 3
2, 1, 1 4 5 (a blank before 3) 4
1, 2, 1 4 5 (a blank before 2) 4
1, 3, 2 6 8 (a blank before 2 and 3) 6
2, 3 5 5 5

Word files a section's even and odd pages by the section's own numbers: the even-page footer
stood on each section's second page, where the page draws it, in both editors.

Edited by hand in the 1, 3 document, Word adds no page in three variants, but each one changes what it shows:

Hand edit Blank page What changes
even and odd pages not stated none the even-page footer is not shown at all
the second section's numbers not restarted none the footer stands on the section's first and third pages, not its second
the numbers restarted at 2 none the footer stands on the section's first and third pages, not its second

So the page cannot be avoided without changing what the page numbers read or where the zones stand.

What changed

  • DocxSemanticBackend.reportTheBlankPageBefore, called for each section after the first
    where the document states different even and odd pages:
    • an APPROXIMATED note, subject page zone, path section N: "Word adds a blank page
      before this section: the section before it runs to one page, and Word starts every section
      on an odd page where the document states different even and odd pages…";
    • read from the page count the layout gives the section before it;
    • where that section has no layout, the note says "where the section before it runs to an
      odd number of pages";
    • the DOCX is written as before.
  • Docs:
    • the DOCX recipe's "Several sections in one document";
    • the capability matrix's multi-section row;
    • CHANGELOG v2.5.0.

Verification

  • DocxBlankPageBeforeSectionTest (new, 5 tests):
    • sections of 1, 1, 1 pages: notes before sections 2 and 3, worded as above;
    • 1, 3, 2: before sections 2 and 3, the second "runs to 3 pages";
    • 2, 1, 1: before section 3 only;
    • 1, 2, 1: before section 2 only;
    • 2, 2: none;
    • no even and odd pages stated: none;
    • a section before with no layout: the "where" note.
  • 5 sabotages, all caught:
    • not named;
    • named without even and odd pages too;
    • parity inverted;
    • an uncounted section taken as even;
    • the first section read instead of the one before.
  • Corpus: 62/62 DOCX byte-identical; report notes 1246 → 1246.
  • ./mvnw -B -ntp clean verify: BUILD SUCCESS (core 821, render-docx 1780, examples 93, qa 1820); the knowledge pack's --check passes.

Lane: render-docx (semantic backend). A report note only; no output change.

Every section of a multi-section document numbers its pages from 1, and
once the document states different even and odd pages, as it does for
a page zone on some of them, Word starts every such section on an odd
page. It adds a blank page before a section whose section before it
runs to an odd number of pages, and the report said nothing. Measured
in Word and LibreOffice on Windows, sections of one, one and one page
came out five pages in Word and three in LibreOffice; two, one and one
five in Word; one, three and two eight. LibreOffice adds none. With the
numbers not restarted, or restarted at 2, or with even and odd pages
not stated, Word adds none either, but each of those changes what the
page numbers read or where the zones stand.

The report now names each section Word adds a page before (page zone),
from the page count the layout gives the section before it, and where
that section has no layout, says where it would. The DOCX is written as
before.
@DemchaAV
DemchaAV merged commit e0eb9ba into 2.5-dev Oct 19, 2026
13 checks passed
@DemchaAV
DemchaAV deleted the fix/docx-blank-page-before-section branch October 19, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant