Forum


Replies: 2   Views: 425
Page-of generating output twice in footer as inline content
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 06-09-2023 - 09:35

Hello,

In the current stable release of phpdocx, page-of type page numbering must be added as block content, as it doesn't support being added as inline content (numerical or alphabetical types support it).

Instead of adding it as a inline content in the text array please add a new block content in the same WordFragment:

$footerWordFragment = new WordFragment($docx, 'defaultFooter');

$ftr = array();
$ftr[] = array('text' => 'Generic footer text ');

$footerWordFragment->addText($ftr);
$footerWordFragment->addPageNumber('page-of');

$docx->addFooter(array('default' => $footerWordFragment));

Or in a table using WordFragments:

$numberingFragment = new WordFragment($docx, 'defaultFooter');
$numberingFragment->addPageNumber('page-of');

$footerWordFragment = new WordFragment($docx, 'defaultFooter');

$valuesTable = array(
  array(
    'Generic footer text ',
    $numberingFragment,
  ),
);

$footerWordFragment->addTable($valuesTable);

$docx->addFooter(array('default' => $footerWordFragment));

We have sent this use case to the dev team and they have added a patch to the testing branch to include support to page-of type as inline content (it will be included in the next stable release). If you need this patch, please send an email to contact[at]phpdocx.com and we'll send you the updated class (please also send if you are using the classic or the namespaces package).

Regards.