Skip to content

fix: emit mirrorMargins in sectPr for Word for Mac PDF export (#74)#75

Merged
forest6511 merged 1 commit into
mainfrom
fix/issue-74-mirror-margins-mac-pdf-export
May 4, 2026
Merged

fix: emit mirrorMargins in sectPr for Word for Mac PDF export (#74)#75
forest6511 merged 1 commit into
mainfrom
fix/issue-74-mirror-margins-mac-pdf-export

Conversation

@forest6511
Copy link
Copy Markdown
Owner

Summary

  • Defensively duplicate <w:mirrorMargins/> inside sectPr so Word for Mac's "Save as PDF" / "Print to PDF" pipeline mirrors verso pages correctly. The element is still emitted in settings.xml per OOXML spec; Word for Windows and LibreOffice ignore unknown sectPr children, so behaviour is unchanged for them.
  • Unblocks KDP paperback workflows that rely on MirrorMargins + MarginGutter to satisfy the 22.225 mm inner-margin requirement (701–828 page band).

Fixes #74.

Why this works

OOXML spec (ECMA-376 §17.15.1.43) places mirrorMargins under CT_Settings, which the current implementation already does. Empirically, Word for Mac's PDF export pipeline only honours the flag when it also appears under sectPr. Word's reader is tolerant of unknown sectPr children (per the spec's Markup Compatibility rules), so duplicating is a low-risk additive change rather than an alternative-location move.

Changes

  • csharp-version/src/MarkdownToDocx.Core/OpenXml/OpenXmlDocumentBuilder.cs: append <w:mirrorMargins/> to sectPr when MirrorMargins == true.
  • csharp-version/tests/MarkdownToDocx.Tests/Integration/MarkdownToDocxIntegrationTests.cs: regression tests verifying both presence (when enabled) and absence (when disabled) in sectPr and settings.xml.

Note: on deserialization the OpenXml SDK exposes the in-sectPr element as OpenXmlUnknownElement (since it is not in the CT_SectPr schema), so the assertions match by LocalName + namespace URI rather than the typed MirrorMargins class.

Test plan

  • dotnet test (320/320 passing locally)
  • New: Build_WithMirrorMargins_ShouldEmitMirrorMarginsInBothSettingsAndSectPr
  • New: Build_WithoutMirrorMargins_ShouldNotEmitMirrorMarginsAnywhere
  • Manual verification on Word for Mac: open generated DOCX, File → Save as PDF, check verso page margins meet KDP 22.225 mm requirement.

#74)

Word for Mac's "Save as PDF" / "Print to PDF" pipelines flatten the mirror on
verso pages when <w:mirrorMargins/> lives only in settings.xml (the
spec-compliant CT_Settings location). Defensively duplicate the element
inside sectPr so the export pipeline picks it up; LibreOffice and Word for
Windows ignore unknown sectPr children, so existing behaviour is preserved.

This unblocks KDP paperback workflows that rely on MirrorMargins +
MarginGutter to satisfy the 22.225 mm inner-margin requirement.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.17%. Comparing base (b2672c8) to head (57ce521).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #75      +/-   ##
==========================================
+ Coverage   89.16%   89.17%   +0.01%     
==========================================
  Files          28       28              
  Lines        1606     1608       +2     
  Branches      205      206       +1     
==========================================
+ Hits         1432     1434       +2     
  Misses        128      128              
  Partials       46       46              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@forest6511 forest6511 merged commit ee63cf7 into main May 4, 2026
3 checks passed
@forest6511 forest6511 deleted the fix/issue-74-mirror-margins-mac-pdf-export branch May 4, 2026 01:47
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.

[BUG] MirrorMargins で Word for Mac PDF export 時に gutter が flatten される (settings.xml ではなく sectPr 配置で回避)

1 participant