From 06bbf18f2bac8048b11240c1da36d5a4247037bb Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 23 Sep 2025 22:29:54 -0500 Subject: [PATCH 1/5] Update Document.php - Implement MirrorMargins and Bookfold --- src/PhpWord/Writer/RTF/Part/Document.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Part/Document.php b/src/PhpWord/Writer/RTF/Part/Document.php index 484393477d..bf64ff4bb3 100644 --- a/src/PhpWord/Writer/RTF/Part/Document.php +++ b/src/PhpWord/Writer/RTF/Part/Document.php @@ -113,9 +113,15 @@ private function writeFormatting() $content .= '\lang' . $langId; $content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs $content .= '\fs' . (Settings::getDefaultFontSize() * 2); // Set the font size in half-points - if ($docSettings->hasEvenAndOddHeaders()) { + if ($docSettings->hasEvenAndOddHeaders() || $docSettings->hasMirrorMargins()) { $content .= '\\facingp'; } + if ($docSettings->hasMirrorMargins()) { + $content .= '\\margmirror'; + } + if ($docSettings->hasBookFoldPrinting()) { + $content .= '\\bookfold\\landscape'; + } $content .= PHP_EOL; return $content; From 33635c11de796e6781f8ed3207ea0693cf0bc160 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 23 Sep 2025 22:43:21 -0500 Subject: [PATCH 2/5] Update Section.php - Implement bookfold --- src/PhpWord/Writer/RTF/Style/Section.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index 598015ed4d..484d583fd3 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -44,8 +44,13 @@ public function write() $content .= '\sectd '; // Size & margin - $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); - $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); + if($this->getParentWriter()->getPhpWord()->getSettings()->hasBookFoldPrinting()) { + $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pghsxn' . round($style->getPageSizeW())); + $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pgwsxn' . round($style->getPageSizeH())/2); + } else { + $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); + $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); + } $content .= ' '; $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop())); $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight())); From 79ccdb38a679609b47ab3652ca925b1fcd73bc48 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 23 Sep 2025 22:45:55 -0500 Subject: [PATCH 3/5] Update 1.5.0.md - Pull #2834 --- docs/changes/1.x/1.5.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes/1.x/1.5.0.md b/docs/changes/1.x/1.5.0.md index b96865bada..f21a0bdd08 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,6 +7,7 @@ ### Bug fixes - Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776) +- Writer RTF: Add mirror margins and bookfold capabilities by [@rasamassen](https://github.com/rasamassen) in [#2834](https://github.com/PHPOffice/PHPWord/pull/2834) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From a99fd294fa0465a9e7b4834c7f0342dab517d9f7 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Tue, 23 Sep 2025 23:00:08 -0500 Subject: [PATCH 4/5] Update Section.php - Fix errors --- src/PhpWord/Writer/RTF/Style/Section.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index 484d583fd3..e3e30f7d82 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -44,9 +44,9 @@ public function write() $content .= '\sectd '; // Size & margin - if($this->getParentWriter()->getPhpWord()->getSettings()->hasBookFoldPrinting()) { + if ($this->getParentWriter() !== null && $this->getParentWriter()->getPhpWord()->getSettings()->hasBookFoldPrinting()) { $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pghsxn' . round($style->getPageSizeW())); - $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pgwsxn' . round($style->getPageSizeH())/2); + $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pgwsxn' . round($style->getPageSizeH()) / 2); } else { $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); From a6099f11a09cf9e306ff572dc8203631cf5dfdd0 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Wed, 24 Sep 2025 09:13:59 -0500 Subject: [PATCH 5/5] Update Section.php - Fix for cases when orientation is already landscape. --- src/PhpWord/Writer/RTF/Style/Section.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index e3e30f7d82..f34210edfe 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -45,8 +45,11 @@ public function write() // Size & margin if ($this->getParentWriter() !== null && $this->getParentWriter()->getPhpWord()->getSettings()->hasBookFoldPrinting()) { - $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pghsxn' . round($style->getPageSizeW())); - $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pgwsxn' . round($style->getPageSizeH()) / 2); + if ($style->getOrientation() !== SectionStyle::ORIENTATION_LANDSCAPE) { + $style->setOrientation(SectionStyle::ORIENTATION_LANDSCAPE); + } + $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW()) / 2); + $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); } else { $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH()));