Skip to content

Permit book-fold printing #2225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ Use mirror margins to set up facing pages for double-sided documents, such as bo

$phpWord->getSettings()->setMirrorMargins(true);

Note that in order for this to work properly, you need to set both paper size and page size. For example,
to print a document on A4 paper (landscape) and fold it into A5 pages (portrait), use this section style:

.. code-block:: php

$phpWord->getSettings()->setMirrorMargins(true);
$phpWord->addSection(array(
'paperSize' => 'A4',
'orientation' => 'landscape',
'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(14.85),
'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(21),
));


Printing as folded booklet
~~~~~~~~~~~~~~~~~~~~~~~~~~
Use book-fold printing to set up documents to be printed as foldable pages.

.. code-block:: php

$phpWord->getSettings()->setBookFoldPrinting(true);

Spelling and grammatical checks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
23 changes: 23 additions & 0 deletions src/PhpWord/Metadata/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ class Settings
*/
private $doNotHyphenateCaps;

/**
* Enable or disable book-folded printing.
*
* @var bool
*/
private $bookFoldPrinting = false;

/**
* @return Protection
*/
Expand Down Expand Up @@ -481,4 +488,20 @@ public function setDoNotHyphenateCaps($doNotHyphenateCaps): void
{
$this->doNotHyphenateCaps = (bool) $doNotHyphenateCaps;
}

/**
* @return bool
*/
public function hasBookFoldPrinting(): bool
{
return $this->bookFoldPrinting;
}

/**
* @param bool $bookFoldPrinting
*/
public function setBookFoldPrinting(bool $bookFoldPrinting): void
{
$this->bookFoldPrinting = $bookFoldPrinting;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->bookFoldPrinting = $bookFoldPrinting;
$this->bookFoldPrinting = $bookFoldPrinting;
return $this;

}
}
1 change: 1 addition & 0 deletions src/PhpWord/Writer/Word2007/Part/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private function getSettings(): void
$this->setOnOffValue('w:updateFields', $documentSettings->hasUpdateFields());
$this->setOnOffValue('w:autoHyphenation', $documentSettings->hasAutoHyphenation());
$this->setOnOffValue('w:doNotHyphenateCaps', $documentSettings->hasDoNotHyphenateCaps());
$this->setOnOffValue('w:bookFoldPrinting', $documentSettings->hasBookFoldPrinting());

$this->setThemeFontLang($documentSettings->getThemeFontLang());
$this->setRevisionView($documentSettings->getRevisionView());
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpWordTests/Writer/Word2007/Part/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,20 @@ public function testDoNotHyphenateCaps(): void
$element = $doc->getElement($path, $file);
self::assertSame('true', $element->getAttribute('w:val'));
}

public function testBookFoldPrinting(): void
{
$phpWord = new PhpWord();
$phpWord->getSettings()->setBookFoldPrinting(true);

$doc = TestHelperDOCX::getDocument($phpWord);

$file = 'word/settings.xml';

$path = '/w:settings/w:bookFoldPrinting';
self::assertTrue($doc->elementExists($path, $file));

$element = $doc->getElement($path, $file);
self::assertSame('true', $element->getAttribute('w:val'));
}
}