Replies: 4   Views: 2858
How can i addimage after header/footer for each page?
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 gh_ost  · 07-12-2017 - 12:44


I have image of the print our company and this print must be on each page before the text ( i know about watermark and background but this methods doesn't solve the problem) of the document.  

I use insertWordFragment, but it's add elements (after/before) like pharapraph, section, break ( break doesn't found with type = "next" like in example) etc. there not element footer or header

        $image = public_path().'/img/ncste_print_q.png';

        $print = new WordFragment($word, 'document');
            'src' => $image,
            'textWrap' => 2,
            'height' => 100,
            'width' => 350

        $word->addBreak(array('type' => 'page'));
        //['type' => 'break', 'attributes' => array('w:type' => 'page'),]
        $word->insertWordFragment($print, ['attributes' => array('w:headerReference' => ''),], 'after' );

So how i can solve this problem?



Posted by admin  · 08-12-2017 - 08:24


background images, watermarks and headers/footers can be used to repeat a content in all pages.

If you are creating the DOCX from scratch, you can add the image as a WordFragment when inserting the header or footer. Please check the examples available for the addHeader ( method.

If you are using a template, please add a placeholder in the header or footer with the program you are using to generate the templates and then replace the placeholder by an image using the replaceVariableByWordfragment ( method setting the right target option.

DOCXPath can only be used with the body content. 


phpdocx support Team

Posted by gh_ost  · 08-12-2017 - 09:12

Sorry you don't understand me 

I want add image on the text not under not before or after this must look like the red stamp this  page  on each page. 

And i am generating document


Posted by gh_ost  · 08-12-2017 - 11:16

Deleted by admin · 08-12-2017 - 20:01

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


We recommend you to use a custom template with an image placeholder and a text placeholder surrounded by block placeholders, and then use the cloneBlock method ( to clone the block as many times as needed. This method is available since phpdocx 7 for Advanced and Premium licenses.

The options relativeFromHorizontal and relativeFromVertical available in the addImage method since phpdocx 7.5 can also help for that task.

But please note there's no a 'perfect' approach for that task, as a DOCX is not like a PDF that is 'painted' in fixed positions. It is more similar to HMTL, as it is painted 'dynamically'; so you should manage the contents of the blocks to avoid creating new extra pages. There's no way to know the content after a header.