2014-03-07 23:08:09 +01:00
< ? php
2014-03-15 22:39:57 +07:00
include_once 'Sample_Header.php' ;
2014-03-07 23:08:09 +01:00
// New Word Document
2014-04-08 21:56:18 +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-04-01 15:01:30 +07:00
\PhpOffice\PhpWord\Settings :: setCompatibility ( false );
2014-03-07 23:08:09 +01:00
// New portrait section
2014-04-02 11:02:56 +07:00
$section = $phpWord -> addSection ();
2014-03-07 23:08:09 +01:00
// Add style definitions
2014-03-20 16:54:12 +04:00
$phpWord -> addParagraphStyle ( 'pStyle' , array ( 'spacing' => 100 ));
$phpWord -> addFontStyle ( 'BoldText' , array ( 'bold' => true ));
$phpWord -> addFontStyle ( 'ColoredText' , array ( 'color' => 'FF8080' ));
2014-03-23 10:32:08 +04:00
$phpWord -> addLinkStyle ( 'NLink' , array ( 'color' => '0000FF' , 'underline' => \PhpOffice\PhpWord\Style\Font :: UNDERLINE_SINGLE ));
2014-03-07 23:08:09 +01:00
// Add text elements
2014-04-02 11:02:56 +07:00
$textrun = $section -> addTextRun ( 'pStyle' );
2014-03-07 23:08:09 +01:00
$textrun -> addText ( 'This is some lead text in a paragraph with a following footnote. ' , 'pStyle' );
2014-04-02 11:02:56 +07:00
$footnote = $textrun -> addFootnote ();
2014-04-01 15:01:30 +07:00
$footnote -> addText ( 'Just like a textrun, a footnote can contain native texts. ' );
$footnote -> addText ( 'No break is placed after adding an element. ' , 'BoldText' );
$footnote -> addText ( 'All elements are placed inside a paragraph. ' , 'ColoredText' );
2014-03-29 00:57:23 +07:00
$footnote -> addTextBreak ();
2014-04-01 15:01:30 +07:00
$footnote -> addText ( 'But you can insert a manual text break like above, ' );
$footnote -> addText ( 'links like ' );
$footnote -> addLink ( 'http://www.google.com' , null , 'NLink' );
2014-04-02 09:01:44 +07:00
$footnote -> addText ( ', image like ' );
2014-04-01 15:01:30 +07:00
$footnote -> addImage ( 'resources/_earth.jpg' , array ( 'width' => 18 , 'height' => 18 ));
2014-04-02 09:01:44 +07:00
$footnote -> addText ( ', or object like ' );
$footnote -> addObject ( 'resources/_sheet.xls' );
2014-04-01 15:01:30 +07:00
$footnote -> addText ( 'But you can only put footnote in section, not in header or footer.' );
2014-03-07 23:08:09 +01:00
$section -> addText ( 'You can also create the footnote directly from the section making it wrap in a paragraph like the footnote below this paragraph. But is is best used from within a textrun.' );
2014-04-02 11:02:56 +07:00
$footnote = $section -> addFootnote ();
2014-03-07 23:08:09 +01:00
$footnote -> addText ( 'The reference for this is wrapped in its own line' );
2014-03-12 21:55:20 +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-12 21:55:20 +07:00
}