Replies: 7   Views: 472
Add pagination and contents to the footers replacing them in an existing docx
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  · 24-12-2021 - 11:10


As explained in our previous reply, addFooter and addHeader methods work only with documents with one section (to generate DOCX documents from scratch with multiple sections and headers/footers the mergeDocx method must be used []).

To replace all headers and footers in an existing DOCX document with one or more sections you need to use the importHeadersAndFooters method.

You can generate a DOCX with headers/footers:

$docx = new CreateDocx();

$footer_html = '<p>Footer HTML</p>';

$numbering = new WordFragment($docx, 'defaultFooter');
$docx->addFooter(array('default' => $numbering, 'first' => $numbering, 'even' => $numbering));


and then use it with importHeadersAndFooters to replace headers/footers in a DOCX template with one or more sections:

$docxNew = new CreateDocxFromTemplate('document_with_header_footer_multiple_sections.docx');

Also note that break (addBreak method and 'type'=>'break' in DOCXPath) don't work with sections but with break tags. If you need to work with sections you need to use the addSection method and 'type' => 'section' in DOCXPath. The removeWordContent method included in DOCXPath removes contents; in the package you can find a lot of samples using it.

If you open a ticket ( attaching a DOCX sample with multiple sections you are using, the dev team will generate a custom script using it.