Skip to content

Commit 8deac5d

Browse files
committed
Permit book-fold printing
1 parent 0af4ca1 commit 8deac5d

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

docs/general.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,28 @@ Use mirror margins to set up facing pages for double-sided documents, such as bo
177177
178178
$phpWord->getSettings()->setMirrorMargins(true);
179179
180+
Note that in order for this to work properly, you need to set both paper size and page size. For example,
181+
to print a document on A4 paper (landscape) and fold it into A5 pages (portrait), use this section style:
182+
183+
.. code-block:: php
184+
185+
$phpWord->getSettings()->setMirrorMargins(true);
186+
$phpWord->addSection(array(
187+
'paperSize' => 'A4',
188+
'orientation' => 'landscape',
189+
'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(14.85),
190+
'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(21),
191+
));
192+
193+
194+
Printing as folded booklet
195+
~~~~~~~~~~~~~~~~~~~~~~~~~~
196+
Use book-fold printing to set up documents to be printed as foldable pages.
197+
198+
.. code-block:: php
199+
200+
$phpWord->getSettings()->setBookFoldPrinting(true);
201+
180202
Spelling and grammatical checks
181203
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182204

src/PhpWord/Metadata/Settings.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ class Settings
160160
*/
161161
private $doNotHyphenateCaps;
162162

163+
/**
164+
* Enable or disable book-folded printing
165+
* @var bool|null
166+
*/
167+
private $bookFoldPrinting;
168+
163169
/**
164170
* @return Protection
165171
*/
@@ -481,4 +487,20 @@ public function setDoNotHyphenateCaps($doNotHyphenateCaps): void
481487
{
482488
$this->doNotHyphenateCaps = (bool) $doNotHyphenateCaps;
483489
}
490+
491+
/**
492+
* @return bool
493+
*/
494+
public function hasBookFoldPrinting()
495+
{
496+
return $this->bookFoldPrinting;
497+
}
498+
499+
/**
500+
* @param bool $bookFoldPrinting
501+
*/
502+
public function setBookFoldPrinting($bookFoldPrinting)
503+
{
504+
$this->bookFoldPrinting = $bookFoldPrinting;
505+
}
484506
}

src/PhpWord/Writer/Word2007/Part/Settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ private function getSettings(): void
151151
$this->setOnOffValue('w:updateFields', $documentSettings->hasUpdateFields());
152152
$this->setOnOffValue('w:autoHyphenation', $documentSettings->hasAutoHyphenation());
153153
$this->setOnOffValue('w:doNotHyphenateCaps', $documentSettings->hasDoNotHyphenateCaps());
154+
$this->setOnOffValue('w:bookFoldPrinting', $documentSettings->hasBookFoldPrinting());
154155

155156
$this->setThemeFontLang($documentSettings->getThemeFontLang());
156157
$this->setRevisionView($documentSettings->getRevisionView());

tests/PhpWordTests/Writer/Word2007/Part/SettingsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,20 @@ public function testDoNotHyphenateCaps(): void
468468
$element = $doc->getElement($path, $file);
469469
self::assertSame('true', $element->getAttribute('w:val'));
470470
}
471+
472+
public function testBookFoldPrinting()
473+
{
474+
$phpWord = new PhpWord();
475+
$phpWord->getSettings()->setBookFoldPrinting(true);
476+
477+
$doc = TestHelperDOCX::getDocument($phpWord);
478+
479+
$file = 'word/settings.xml';
480+
481+
$path = '/w:settings/w:bookFoldPrinting';
482+
$this->assertTrue($doc->elementExists($path, $file));
483+
484+
$element = $doc->getElement($path, $file);
485+
$this->assertSame('true', $element->getAttribute('w:val'));
486+
}
471487
}

0 commit comments

Comments
 (0)