Forum


Replies: 5   Views: 459
Force header "different first page" option to false
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  · 02-07-2026 - 10:07

Hello,

Please note that the importHeadersAndFooters method may not generate the exact output in your case because the setDefault option changes all targets, including the "even" position in headers/footers.
For this specific case, we recommend using the DOCXCustomizer approach detailed in our previous reply.

Regarding the importHeadersAndFooters method, please note that this is a CreateDocx method (although CreateDocxFromTemplate inherits it).
In this case, the imported headers and footers are not available unless you load the DOCX containing the imported headers and footers as a new template:

$docx = new CreateDocxFromTemplate('sample_1_upd.docx');
$wordTemplateVariablesArray = $docx->getTemplateVariables();

$docx->importHeadersAndFooters('sample_1_upd.docx', 'headerAndFooter', ['setDefault' => true]);

$docx->createDocx('sample_1_upd_importHeadersAndFooters');

$docx = new CreateDocxFromTemplate('sample_1_upd_importHeadersAndFooters.docx');
$wordTemplateVariablesArray = $docx->getTemplateVariables();
$docx->createDocx('output');

You could also use in-memory DOCX (https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents) to avoid generating temp files:

$docx = new CreateDocxFromTemplate('sample_1_upd.docx');
CreateDocx::$returnDocxStructure = true;
$wordTemplateVariablesArray = $docx->getTemplateVariables();

$docx->importHeadersAndFooters('sample_1_upd.docx', 'headerAndFooter', ['setDefault' => true]);
$docxStructureTemplate = $docx->createDocx();
CreateDocx::$returnDocxStructure = false;

$docx = new CreateDocxFromTemplate($docxStructureTemplate);
$wordTemplateVariablesArray = $docx->getTemplateVariables();
$docx->createDocx('output');

We have forwarded this task to the dev team to improve this workflow in future releases of phpdocx.

Regards.