Forum


Replies: 1   Views: 2043
Add two items in the footer
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  · 29-10-2019 - 07:51

Hello,

You can add more than one content to the same WordFragment:

$footerWordFragment = new WordFragment($docx, 'defaultFooter');
$optionsLeft = array(
    'textAlign' => 'left',
);
$footerWordFragment->addText('Footer text', $optionsLeft);

$optionsRight = array(
    'textAlign' => 'right',
);
$footerWordFragment->addPageNumber('numerical', $optionsRight);

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

But to accomplish your task and get a correct vertical alignment for both contents (and more if needed), we recommend you to use a table:

$footerWordFragmentText = new WordFragment($docx, 'defaultFooter');
$optionsLeft = array(
    'textAlign' => 'left'
);
$footerWordFragmentText->addText('Footer text', $optionsLeft);

$footerWordFragmentPageNumber = new WordFragment($docx, 'defaultFooter');
$optionsRight = array(
    'textAlign' => 'right'
);
$footerWordFragmentPageNumber->addPageNumber('numerical', $optionsRight);

$valuesTable = array(
    array(
        $footerWordFragmentText,
        $footerWordFragmentPageNumber,
    ),
);

$paramsTable = array(
    'tableStyle' => 'LightListAccent1PHPDOCX',
    'tableAlign' => 'center',
    'columnWidths' => array(3000, 3000),
);

$footerWordFragmentTable = new WordFragment($docx, 'defaultFooter');
$footerWordFragmentTable->addTable($valuesTable, $paramsTable);

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

Or you can use a custom template (https://www.phpdocx.com/documentation/practical/headers-and-footers) or import headers and footers from an external DOCX (https://www.phpdocx.com/api-documentation/layout-and-general/import-headers-and-footers-Word-document-with-PHP).

Regards.