Replies: 16   Views: 4380
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 Simco uwkm  · 19-12-2017 - 14:35

$headerImageOptions = array(
        'src' => __DIR__ . '/../../Resources/Public/Images/simco_header.png', 
        'dpi' => 300,  
$footerImageOptions = array(
        'src' => __DIR__ . '/../../Resources/Public/Images/simco_footer.png', 
        'dpi' => 300,  
$headerImage = new \Phpdocx\Elements\WordFragment($docx, 'defaultHeader');

$footerImage = new \Phpdocx\Elements\WordFragment($docx, 'defaultFooter');

$docx->addHeader(array('default' => $headerImage));
$docx->addFooter(array('default' => $footerImage));

it's not showing  there as image, but as red cross with message that probably it has not enough memory to display it there or the image was damaged.

how can it be fixed ?

Posted by admin  · 19-12-2017 - 15:00


Please check and run the included examples of adding headers ( and footers ( Both methods are working perfectly.

You can find the same samples in the package. Also please check that the images have the correct extension for their mime-types (for example you are not adding a JPEG using a PNG extension file).

Please note that addHeader and addFooter methods can be used when creating a DOCX from scratch. If you are using a template you need to set placeholders in the template or import the headers/footers from an existing DOCX ( If you need to mix both (templates and created from scratch) please use the mergeDocx method (,


Posted by Simco uwkm  · 19-12-2017 - 15:43

It was showing yesterday but only on last page, after modifying template and replacing placeholders with sections and  embedhtml i get this issue.
Checked  images - mime type is png. Path to image is also correct one.

you can see document here :
and for template it's:
path to image :

so not really sure what could be else go wrong here.

Posted by admin  · 19-12-2017 - 16:20


If you are using a template and then you need to add new content with headers and footers created from scratch, we recommend you to use the generate each DOCX standalone and the use the mergeDocx method:

1. Replace the contents of the template (this is the cover).

2. Create a new DOCX with the new contents, headers, footers.

3. Merge both DOCX using the mergeDOCX method (

There's also an article about this approach ( The addHeader and addFooter methods should only be used for DOCX created from scratch.

Or you could create a single template with the cover and a new page with a placeholder image for the headers and footers.


Posted by Simco uwkm  · 20-12-2017 - 08:08

Tested with creating single document and merge them together.
in merged and in single i do have same issue headers and footers showing  same no image.

double checked path and mime type they are correct ones.

Posted by Simco uwkm  · 20-12-2017 - 08:17

if i set image to 72dpi it show me only one on single page, rest of the pages continue to display no image.

my guess here that it runs indeed out of memory although in php.ini i have set it to 2Gb

Posted by admin  · 20-12-2017 - 08:55


If PHP throws an out of memory message, it is registered in the log of the server. Do you see that out of memory message in your server logs? Please also test your script using PHP CLI mode.

We have done some tests (doing the merging and working with a single template) with your DOCX and images and everything is working correctly.

Also please run the included samples in the package (LayoutAndGeneral folder: addHeader and addFooter) and check if the images are added correctly.


Posted by Simco uwkm  · 20-12-2017 - 09:21

No absolutely nothing in logs,  now made html part for header and tried to insert that as header. 
still image gives me cross.
although if i say not to download images while embedding html word document says that the document is broken.

we use php 7.0 if that makes any difference.

Posted by admin  · 20-12-2017 - 09:23


Please run the included samples in the package (LayoutAndGeneral folder: addHeader and addFooter) and check if the images are added and they appear correctly.

The URL you have posted with your DOCX is broken.

About PHP version, phpdocx is fully tested with PHP 5.2 to PHP 7.1 (including all the versions from PHP 5.2: PHP 5.3, PHP 5.4...PHP 7.0 and PHP 7.2 beta).



Posted by Simco uwkm  · 20-12-2017 - 09:26

modified url to file.. donno from where  but got strange characters there.
tested package examples everything works just fine.

is it possible that document bugs from the image path ?

Posted by admin  · 20-12-2017 - 09:31


Now please run the same scripts included in the package but adding your images. Please change only the path to the image, not how it's being added (just copy the new image and change the path in the script). Please test it using the most simple script: examples/addHeader/sample_1.php


Posted by Simco uwkm  · 20-12-2017 - 10:25

now i'm totaly lost, just have this code in my extension:

namespace UWKM\UwkmOffer\Controller;

class OfferController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController

        public function submitAction()

                require_once(__DIR__ . '/../../Lib/Classes/Phpdocx/');

                $docx = new \Phpdocx\Create\CreateDocx();
                $footerImageOptions = array(
                        'src' => __DIR__ . '/../../Resources/Public/Images/simco_footer.png', 
                $footerImage = new \Phpdocx\Elements\WordFragment($docx, 'defaultFooter');
                $headerElements = new \Phpdocx\Elements\WordFragment($docx, 'headers');
                $headView = $this->offerRepository->getTemplateHtml('Offer', 'header');
                $headView->assign('image', __DIR__ .'/../../Resources/Public/Images/simco_header2.png');
                $headView->assign('addressInfo', 'Simco-ION
Aalsvoort 74
7241 MB Lochem
The Netherlands
+31 (0)753 288378
+31 (0)573 288390');

                $headerElements->embedHTML($headView->render(), array('downloadImages'=>true));
                $docx->addHeader(array('first'=>$headerElements, 'default' => $headerElements));
                $docx->addFooter(array('first'=>$footerImage,'default' => $footerImage));

wel resulting docx is without images here. is it bugging due script using namespace too ?

Posted by admin  · 20-12-2017 - 10:26


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:


require_once 'Classes/Phpdocx/Create/';

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

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

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


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



$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');


Posted by Simco uwkm  · 20-12-2017 - 10:50

made standalon script to test the code it does work just fine.. but when it's placed within extension it gives me those bugs.. 

things are really weird.. 

Posted by admin  · 20-12-2017 - 10:56


Sorry but if it's working standalone, we have tested with the change in your DOCX explained on our previous update and the output is correct, then there must be something wrong about how it's being used/integrated with the CMS that we can't guess.

The namespaces package is fully tested with CMS such as WordPress and Drupal and frameworks (Symfony, Laravel, Yii, CakePHP...). Type3 should work fine too, and we are aware that other users are using phpdocx namespaces with Type3 without issues.

We recommend you to try using the included samples in your Controller, maybe it can't read the images due to some missing rw access.


Posted by Simco uwkm  · 20-12-2017 - 11:23

found out what was wrong with it.. it didn't like 

$docx->addHeader(array('first'=>$headerElements,'default' => $headerElements));

now have just :

$docx->addHeader(array('default' => $headerElements));

and that works just fine.