2014-03-14 00:04:52 +07:00
< ? php
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 ();
2015-02-06 22:28:31 +04:00
$textrun -> addText ( htmlspecialchars ( 'This is the header with ' , ENT_COMPAT , 'UTF-8' ));
$textrun -> addLink ( 'https://github.com/PHPOffice/PHPWord' , htmlspecialchars ( 'PHPWord on GitHub' , ENT_COMPAT , 'UTF-8' ));
2015-10-10 19:22:19 +04:00
$table -> addCell ( 4500 ) -> addImage ( 'resources/PhpWord.png' , array ( '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 ();
2015-02-06 22:28:31 +04:00
$subsequent -> addText ( htmlspecialchars ( 'Subsequent pages in Section 1 will Have this!' , ENT_COMPAT , 'UTF-8' ));
2014-05-05 09:08:15 +07:00
$subsequent -> addImage ( 'resources/_mars.jpg' , array ( '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 ();
2015-10-10 19:22:19 +04:00
$footer -> addPreserveText ( htmlspecialchars ( 'Page {PAGE} of {NUMPAGES}.' , ENT_COMPAT , 'UTF-8' ), null , array ( 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc :: CENTER ));
2015-02-06 22:28:31 +04:00
$footer -> addLink ( 'https://github.com/PHPOffice/PHPWord' , htmlspecialchars ( 'PHPWord on GitHub' , ENT_COMPAT , 'UTF-8' ));
2014-03-14 00:04:52 +07:00
// Write some text
$section -> addTextBreak ();
2015-02-06 22:28:31 +04:00
$section -> addText ( htmlspecialchars ( 'Some text...' , ENT_COMPAT , 'UTF-8' ));
2014-03-14 00:04:52 +07:00
// Create a second page
$section -> addPageBreak ();
// Write some text
$section -> addTextBreak ();
2015-02-06 22:28:31 +04:00
$section -> addText ( htmlspecialchars ( 'Some text...' , ENT_COMPAT , 'UTF-8' ));
2014-03-14 00:04:52 +07:00
// Create a third page
$section -> addPageBreak ();
// Write some text
$section -> addTextBreak ();
2015-02-06 22:28:31 +04:00
$section -> addText ( htmlspecialchars ( 'Some text...' , ENT_COMPAT , 'UTF-8' ));
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 ();
2015-02-06 22:28:31 +04:00
$sec2Header -> addText ( htmlspecialchars ( 'All pages in Section 2 will Have this!' , ENT_COMPAT , 'UTF-8' ));
2014-03-14 00:04:52 +07:00
// Write some text
$section2 -> addTextBreak ();
2015-02-06 22:28:31 +04:00
$section2 -> addText ( htmlspecialchars ( 'Some text...' , ENT_COMPAT , 'UTF-8' ));
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
}