forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample_08_ParagraphPagination.php
89 lines (80 loc) · 2.89 KB
/
Sample_08_ParagraphPagination.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(
array(
'alignment' => 'both',
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
'spacing' => 120,
)
);
// Sample
$section = $phpWord->addSection();
$section->addText(
htmlspecialchars(
'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.',
ENT_COMPAT,
'UTF-8'
),
array('bold' => true),
array('space' => array('before' => 360, 'after' => 480))
);
$section->addText(
htmlspecialchars(
'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.',
ENT_COMPAT,
'UTF-8'
),
null,
array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
);
$section->addText(
htmlspecialchars(
'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.',
ENT_COMPAT,
'UTF-8'
),
null,
array('keepNext' => true, 'indentation' => array('firstLine' => 240))
);
$section->addText(
htmlspecialchars(
'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.',
ENT_COMPAT,
'UTF-8'
),
null,
array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))
);
$section->addText(htmlspecialchars('Keep scrolling. More below.', ENT_COMPAT, 'UTF-8'));
$section->addText(
htmlspecialchars(
'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.',
ENT_COMPAT,
'UTF-8'
),
null,
array('pageBreakBefore' => true)
);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}