Forum


Replies: 2   Views: 422
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 robbed  · 05-09-2023 - 21:40

I am trying to create a single line footer with text, two links, a date and a page number. Everything works fine when I use 'numbering' as the type parameter for the page numbers but when I try to use 'page-of' it generates the output twice.

Here is a simplified version of the code for my footer that still demonstrates the issue:

require_once 'classes/CreateDocx.php';

$docx = new CreateDocx();

$numbering = new WordFragment($docx);
$numbering->addPageNumber('page-of');

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

$footerWordFragment = new WordFragment($docx);

$footerWordFragment->addText($ftr);

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

$docx->addText('This is the first page.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the second page.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the third page.');

$docx->createDocx('output');

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.

Posted by robbed  · 06-09-2023 - 14:47

I emailed for the patch as you suggested and received it in less than half an hour. It worked flawlessly.

Absolutely phenomenal customer service!