PHPWord/samples/Sample_03_Sections.php

53 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
2022-09-16 11:45:45 +02:00
2019-02-05 21:42:14 +01:00
use PhpOffice\PhpWord\SimpleType\VerticalJc;
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();
// New portrait section
2022-09-16 11:45:45 +02:00
$section = $phpWord->addSection(['borderColor' => '00FF00', 'borderSize' => 12]);
2016-06-04 20:06:37 +04:00
$section->addText('I am placed on a default section.');
// New landscape section
2022-09-16 11:45:45 +02:00
$section = $phpWord->addSection(['orientation' => 'landscape']);
2016-06-04 20:06:37 +04:00
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak();
$section->addPageBreak();
// New portrait section
2015-01-01 20:41:42 +04:00
$section = $phpWord->addSection(
2022-09-16 11:45:45 +02:00
['paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600]
2015-01-01 20:41:42 +04:00
);
2016-06-04 20:06:37 +04:00
$section->addText('This section uses other margins with folio papersize.');
2019-02-05 21:42:14 +01:00
// The text of this section is vertically centered
$section = $phpWord->addSection(
2022-09-16 11:45:45 +02:00
['vAlign' => VerticalJc::CENTER]
2019-02-05 21:42:14 +01:00
);
$section->addText('This section is vertically centered.');
// New portrait section with Header & Footer
2015-01-01 20:41:42 +04:00
$section = $phpWord->addSection(
2022-09-16 11:45:45 +02:00
[
'marginLeft' => 200,
'marginRight' => 200,
'marginTop' => 200,
2015-01-01 20:41:42 +04:00
'marginBottom' => 200,
'headerHeight' => 50,
'footerHeight' => 50,
2022-09-16 11:45:45 +02:00
]
2015-01-01 20:41:42 +04:00
);
2016-06-04 20:06:37 +04:00
$section->addText('This section and we play with header/footer height.');
$section->addHeader()->addText('Header');
$section->addFooter()->addText('Footer');
// Save file
2014-04-12 10:12:24 +07:00
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}