2014-03-14 00:04:52 +07:00
|
|
|
<?php
|
2022-09-16 11:45:45 +02:00
|
|
|
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// New Word document
|
2015-01-01 20:41:42 +04:00
|
|
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
2014-03-23 10:32:08 +04:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// New portrait section
|
2014-04-02 11:02:56 +07:00
|
|
|
$section = $phpWord->addSection();
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Add first page header
|
2014-04-02 11:02:56 +07:00
|
|
|
$header = $section->addHeader();
|
2014-03-14 00:04:52 +07:00
|
|
|
$header->firstPage();
|
|
|
|
|
$table = $header->addTable();
|
|
|
|
|
$table->addRow();
|
2014-04-01 15:01:30 +07:00
|
|
|
$cell = $table->addCell(4500);
|
|
|
|
|
$textrun = $cell->addTextRun();
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun->addText('This is the header with ');
|
|
|
|
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
2022-09-16 11:45:45 +02:00
|
|
|
$table->addCell(4500)->addImage('resources/PhpWord.png', ['width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END]);
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Add header for all other pages
|
2014-04-02 11:02:56 +07:00
|
|
|
$subsequent = $section->addHeader();
|
2016-06-04 20:06:37 +04:00
|
|
|
$subsequent->addText('Subsequent pages in Section 1 will Have this!');
|
2022-09-16 11:45:45 +02:00
|
|
|
$subsequent->addImage('resources/_mars.jpg', ['width' => 80, 'height' => 80]);
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Add footer
|
2014-04-02 11:02:56 +07:00
|
|
|
$footer = $section->addFooter();
|
2022-09-16 11:45:45 +02:00
|
|
|
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', null, ['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$footer->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Write some text
|
|
|
|
|
$section->addTextBreak();
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Some text...');
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Create a second page
|
|
|
|
|
$section->addPageBreak();
|
|
|
|
|
|
|
|
|
|
// Write some text
|
|
|
|
|
$section->addTextBreak();
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Some text...');
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Create a third page
|
|
|
|
|
$section->addPageBreak();
|
|
|
|
|
|
|
|
|
|
// Write some text
|
|
|
|
|
$section->addTextBreak();
|
2016-06-04 20:06:37 +04:00
|
|
|
$section->addText('Some text...');
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// New portrait section
|
2014-04-02 11:02:56 +07:00
|
|
|
$section2 = $phpWord->addSection();
|
2014-03-14 00:04:52 +07:00
|
|
|
|
2014-04-02 11:02:56 +07:00
|
|
|
$sec2Header = $section2->addHeader();
|
2016-06-04 20:06:37 +04:00
|
|
|
$sec2Header->addText('All pages in Section 2 will Have this!');
|
2014-03-14 00:04:52 +07:00
|
|
|
|
|
|
|
|
// Write some text
|
|
|
|
|
$section2->addTextBreak();
|
2016-06-04 20:06:37 +04:00
|
|
|
$section2->addText('Some text...');
|
2014-03-14 00:04:52 +07: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';
|
2014-03-14 00:04:52 +07:00
|
|
|
}
|