Forum


Replies: 2   Views: 2910
How do i used addheader to add a blank header for letter headed paper to every 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 jamie3000  · 02-11-2016 - 15:56

I have a letter that is going to be printed by several clients all with varying sizes of letter headed paper. The header on their paper being different sizes not the paper. So I'd like to be able to dynamically specify a different size blank header each time a letter is generated depending on the client so whe the letter is printed by they it doesn't print all over the head on their letters. Whats the best way of using addHeader to add blank headers to pages?

I've tried addText("\n\r\n\r\n")

I've tried embedding html into a word fragement with a div of a fixed height.

What would you suggest? 

Posted by admin  · 03-11-2016 - 08:47

Hello,

The easiest solution is to use the embedHTML method adding <br> tags:

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$wf = new WordFragment($docx, 'defaultHeader');
$wf->embedHTML('<br><br><br><br>');

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

$docx->addText('Document content');

$docx->createDocx('output');

Or you could use addBreak to add breaks in the WordFragment added to the header.

If the number of headers is limited, you could created empty DOCX templates with the headers and import them using the importHeadersAndFooters method. This method removes existing headers.

Regards.

Posted by jamie3000  · 03-11-2016 - 15:22

Thank you that works very well :-)