Cookbook
- Learn phpdocx in 5 minutes
- Tutorial
- API quick guide
- HTML to Word
- HTML Extended
- Conversion plugin
- Word to HTML
- DOCXPath
- Bulk processing
- DOCXCustomizer
- Digital signature
- Cryptophpdocx
- Right to left languages
- phpdocx CLI command
- Tracking
- Artificial Intelligence
- Blockchain for documents
- JavaScript API
- Compiled mode
Generate different headers and footers for multiple sections
If you need to create headers and footers dynamically for multiple sections, you must use an Advanced or Premium license.
There are two approaches to accomplish this task:
- Use the addHeaderSection and addFooterSection methods.
- Use the MultiMerge class with the mergeDocx method.
To illustrate both possibilities, let's prepare a cover page with no headers or footers in the first page, and then a second page with only a footer and the rest of the pages filled with both headers and footers using sections.
Using addHeaderSection and addFooterSetion methods
This is the easiest approach to generate different headers and footers for sections:
Using MultiMerge features
This approach creates a document for each combination of headers and footers and then merges them all in a single DOCX instead of generating a single document with different types of headers and footers:
Premium licenses allow doing all these steps using in-memory DOCX to get the best performace.