Forum


Replies: 16   Views: 4548
Header and footer not showing
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-12-2017 - 10:26

Hello,

OK, we have found the problem. The DOCX you are using as cover has 'Different Odd & Even pages' enabled for headers and footers (<w:evenAndOddHeaders/> tag in the settings.xml file), so when you merge both DOCX (cover and the DOCX with contents), odd pages have the headers but not even pages as the settings.xml from the first DOCX is used.

You just need to change your cover inserting an empty header and disable the option 'Different Odd & Even Pages' in the "Header & Footer Tools Design" tab.

If you use this cover changed and then run this script:

<?php

require_once 'Classes/Phpdocx/Create/CreateDocx.inc';

$docx = new Phpdocx\Create\CreateDocx();

$imageOptions = array(
        'src' => 'simco_footer.png',
        'dpi' => 300,
);

$headerImage = new Phpdocx\Elements\WordFragment($docx, 'defaultHeader');
$headerImage->addImage($imageOptions);
$docx->addHeader(array('default' => $headerImage));

$docx->addText('Page.');

$docx->addBreak(array('type' => 'page'));

$docx->addText('Page.');

$docx->createDocx('output');

$merge = new Phpdocx\Utilities\MultiMerge();
$merge->mergeDocx('Quotation_front_nl.docx', array('output.docx'), 'output_merge.docx', array());

The header will appear in all pages but the cover one.

About your code, you are using a wrong target (headers is not a valid value):

$headerElements = new \Phpdocx\Elements\WordFragment($docx, 'headers');

Regards.