2014-03-07 23:08:09 +01:00
|
|
|
<?php
|
2022-09-16 11:45:45 +02:00
|
|
|
|
2017-07-04 15:04:30 +02:00
|
|
|
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
|
|
|
|
|
use PhpOffice\PhpWord\SimpleType\NumberFormat;
|
2017-05-30 00:31:32 +02:00
|
|
|
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2014-03-07 23:08:09 +01: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-04-01 15:01:30 +07:00
|
|
|
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
2014-03-07 23:08:09 +01:00
|
|
|
|
2016-06-04 20:06:37 +04:00
|
|
|
// Define styles
|
|
|
|
|
$paragraphStyleName = 'pStyle';
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addParagraphStyle($paragraphStyleName, ['spacing' => 100]);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
|
|
|
|
$boldFontStyleName = 'BoldText';
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addFontStyle($boldFontStyleName, ['bold' => true]);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
|
|
|
|
$coloredFontStyleName = 'ColoredText';
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addFontStyle($coloredFontStyleName, ['color' => 'FF8080', 'bgColor' => 'FFFFCC']);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
|
|
|
|
$linkFontStyleName = 'NLink';
|
2022-09-16 11:45:45 +02:00
|
|
|
$phpWord->addLinkStyle($linkFontStyleName, ['color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE]);
|
2016-06-04 20:06:37 +04:00
|
|
|
|
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 text elements
|
2016-06-04 20:06:37 +04:00
|
|
|
$textrun = $section->addTextRun($paragraphStyleName);
|
|
|
|
|
$textrun->addText('This is some lead text in a paragraph with a following footnote. ', $paragraphStyleName);
|
2014-03-07 23:08:09 +01:00
|
|
|
|
2014-04-02 11:02:56 +07:00
|
|
|
$footnote = $textrun->addFootnote();
|
2016-06-04 20:06:37 +04:00
|
|
|
$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
|
|
|
|
|
$footnote->addText('No break is placed after adding an element. ', $boldFontStyleName);
|
|
|
|
|
$footnote->addText('All elements are placed inside a paragraph. ', $coloredFontStyleName);
|
2014-03-29 00:57:23 +07:00
|
|
|
$footnote->addTextBreak();
|
2016-06-04 20:06:37 +04:00
|
|
|
$footnote->addText('But you can insert a manual text break like above, ');
|
|
|
|
|
$footnote->addText('links like ');
|
|
|
|
|
$footnote->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName);
|
|
|
|
|
$footnote->addText(', image like ');
|
2022-09-16 11:45:45 +02:00
|
|
|
$footnote->addImage('resources/_earth.jpg', ['width' => 18, 'height' => 18]);
|
2016-06-04 20:06:37 +04:00
|
|
|
$footnote->addText(', or object like ');
|
2014-04-02 09:01:44 +07:00
|
|
|
$footnote->addObject('resources/_sheet.xls');
|
2016-06-04 20:06:37 +04:00
|
|
|
$footnote->addText('But you can only put footnote in section, not in header or footer.');
|
2014-03-07 23:08:09 +01:00
|
|
|
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addText(
|
2016-06-04 20:06:37 +04:00
|
|
|
'You can also create the footnote directly from the section making it wrap in a paragraph '
|
2017-05-30 00:31:32 +02:00
|
|
|
. 'like the footnote below this paragraph. But is best used from within a textrun.'
|
2015-01-01 20:41:42 +04:00
|
|
|
);
|
2014-04-02 11:02:56 +07:00
|
|
|
$footnote = $section->addFootnote();
|
2016-06-04 20:06:37 +04:00
|
|
|
$footnote->addText('The reference for this is wrapped in its own line');
|
2014-03-07 23:08:09 +01:00
|
|
|
|
2017-05-30 00:31:32 +02:00
|
|
|
$footnoteProperties = new FootnoteProperties();
|
2017-07-04 15:04:30 +02:00
|
|
|
$footnoteProperties->setNumFmt(NumberFormat::DECIMAL_ENCLOSED_CIRCLE);
|
2017-05-30 00:31:32 +02:00
|
|
|
$section->setFootnoteProperties($footnoteProperties);
|
|
|
|
|
|
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
|
|
|
}
|