Hello,
What version and license of phpdocx are you using?
Please note that DOCX documents don't work internally with pages but with sections. Sections and contents generate pages. A DOCX is 'painted' dynamically, for this reason, the output of a DOCX may change depending on the DOCX reader.
MS Word doesn't include a last page target for headers or footers, only first, default and even targets are available.
You can insert content at the bottom of the last page by following one of the following approaches:
- Generate a new section and add a new footer using addSection and addFooterSection (Advanced or Premium licenses):
// a new document and a template with CreateDocxFromTemplate can be used
$docx = new CreateDocx();
$docx->addText('Content in the first section');
// add a new section
$docx->addSection();
$footerContent = new WordFragment($docx, 'firstFooter');
$footerContent->addText('Footer content');
// by default, addFooterSection adds the footers into the last section
$docx->addFooterSection(array('default' => $footerContent));
$docx->createDocx('output');
This code generates a new section with a new page where the new footer is added, so it may not be adequate.
- Insert a floating table to add content at the bottom of the last page in existing sections (Premium licenses):
// a new document and a template with CreateDocxFromTemplate can be used
$docx = new CreateDocx();
$text = 'Content in the first page.';
$docx->addText($text);
// page break to illustrate the code. Page breaks are not needed to insert floating tables
$docx->addBreak(array('type' => 'page'));
$text = 'Content in the second page.';
$docx->addText($text);
// add a floating table as last content
$valuesTable = array(
array(11, 12, 13, 14),
array(21, 22, 23, 24),
);
$paramsTable = array(
'border' => 'single',
'tableAlign' => 'center',
'float' => array(
'align' => 'center',
),
);
$docx->addTable($valuesTable, $paramsTable);
// change only the last tblPr node to remove the default floating position and set the relative vertical position (w:tblpYSpec) as bottom and the vertical anchor (w:vertAnchor) as margin
$referenceNode = array(
'customQuery' => '//w:tblpPr[last()]',
);
// w:tblpY value is set as twips
$docx->customizeWordContent($referenceNode,
array('customAttributes' => array('w:tblpYSpec' => 'bottom', 'w:vertAnchor' => 'margin'))
);
$docx->createDocx('output');
Supported tblpYSpec values: center, inside, bottom, outside, inline and top.
Supported vertAnchor values: margin, page and text.
These sample codes work with DOCX documents created from scratch and using DOCX templates.
Regards.