Forum


Replies: 1   Views: 2272
Different headers and footers
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  · 20-04-2020 - 13:43

Hello,

Before answering your question, it's important to understand that DOCX documents don't work with pages but sections. Each section can fill one or more pages (even less than one page using continuous sections) and they may contain or not headers/footers. The number of pages and the position of the contents in a DOCX may vary based on the DOCX reader and its compatibility with the OOXML standard.

phpdocx allows working with headers and footers in the same way than MS Word (also compatible with LibreOffice, Google Docs and other DOCX readers):

· Setting first, default and even values that set the different available values to set headers and footers in a section: addHeader, addFooter. This is also compatible with HTML Extended.

· Adding more than one section with headers/footers. To accomplish this task, DOCX documents must be generated as standalone documents (one for each section with headers/footers) and then merge using mergeDocx. This approach is explained on https://www.phpdocx.com/documentation/cookbook/headers-and-footers-for-sections

To be able to change headers and footers, since phpdocx 9.5, DOCXPath includes support for headers and footers. But to be able to change them, these contents must exist in the DOCX (empty or with contents), so you can query them and add/change/remove contents based on the section. There's no the method to get content knowing the page number.

There's no alternative way to work with headers/footers when working with phpdocx. You need to use sections as MS Word does.

Regards.