PHPWord/samples/Sample_08_ParagraphPagination.php

71 lines
2.4 KiB
PHP
Raw Permalink Normal View History

<?php
2022-09-16 11:45:45 +02:00
2014-03-15 22:39:57 +07:00
include_once 'Sample_Header.php';
// New Word document
2015-01-01 20:41:42 +04:00
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
2015-01-01 20:41:42 +04:00
$phpWord->setDefaultParagraphStyle(
2022-09-16 11:45:45 +02:00
[
'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::BOTH,
2015-01-01 20:41:42 +04:00
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
2022-09-16 11:45:45 +02:00
'spacing' => 120,
]
2015-01-01 20:41:42 +04:00
);
2016-06-04 20:06:37 +04:00
// New section
$section = $phpWord->addSection();
2015-01-01 20:41:42 +04:00
$section->addText(
2016-06-04 20:06:37 +04:00
'Below are the samples on how to control your paragraph '
. 'pagination. See "Line and Page Break" tab on paragraph properties '
. 'window to see the attribute set by these controls.',
2022-09-16 11:45:45 +02:00
['bold' => true],
['space' => ['before' => 360, 'after' => 480]]
2015-01-01 20:41:42 +04:00
);
$section->addText(
2016-06-04 20:06:37 +04:00
'Paragraph with widowControl = false (default: true). '
. 'A "widow" is the last line of a paragraph printed by itself at the top '
. 'of a page. An "orphan" is the first line of a paragraph printed by '
. 'itself at the bottom of a page. Set this option to "false" if you want '
. 'to disable this automatic control.',
2015-01-01 20:41:42 +04:00
null,
2022-09-16 11:45:45 +02:00
['widowControl' => false, 'indentation' => ['left' => 240, 'right' => 120]]
2015-01-01 20:41:42 +04:00
);
$section->addText(
2016-06-04 20:06:37 +04:00
'Paragraph with keepNext = true (default: false). '
. '"Keep with next" is used to prevent Word from inserting automatic page '
. 'breaks between paragraphs. Set this option to "true" if you do not want '
. 'your paragraph to be separated with the next paragraph.',
2015-01-01 20:41:42 +04:00
null,
2022-09-16 11:45:45 +02:00
['keepNext' => true, 'indentation' => ['firstLine' => 240]]
2015-01-01 20:41:42 +04:00
);
$section->addText(
2016-06-04 20:06:37 +04:00
'Paragraph with keepLines = true (default: false). '
. '"Keep lines together" will prevent Word from inserting an automatic page '
. 'break within a paragraph. Set this option to "true" if you do not want '
. 'all lines of your paragraph to be in the same page.',
2015-01-01 20:41:42 +04:00
null,
2022-09-16 11:45:45 +02:00
['keepLines' => true, 'indentation' => ['left' => 240, 'hanging' => 240]]
2015-01-01 20:41:42 +04:00
);
2016-06-04 20:06:37 +04:00
$section->addText('Keep scrolling. More below.');
2015-01-01 20:41:42 +04:00
$section->addText(
2016-06-04 20:06:37 +04:00
'Paragraph with pageBreakBefore = true (default: false). '
. 'Different with all other control above, "page break before" separates '
. 'your paragraph into the next page. This option is most useful for '
. 'heading styles.',
2015-01-01 20:41:42 +04:00
null,
2022-09-16 11:45:45 +02:00
['pageBreakBefore' => true]
2015-01-01 20:41:42 +04:00
);
// Save file
2014-04-12 10:12:24 +07:00
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}