Forum


Replies: 5   Views: 3469
Add header starting from page 2 onwards
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 anjanesh  · 10-03-2016 - 06:47

Is it possible to add header starting from page 2 ? Im using a template for page 1 which contains a background image.

$docx = new CreateDocxFromTemplate("template.docx");

$variables = [
    'SIGN' => "Testing Sign"
    ];

# Page 1 - import from template
$docx->replaceVariableByText($variables);

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

$textOptions = [
'b' => 'on',
'color' => '567899',
'backgroundColor' => 'feac0a',
'textAlign' => 'center'
];

$header = new WordFragment($docx, 'defaultHeader');
$header->addText("Header", $textOptions);

$docx->addHeader(array('default' => $header)); # I want this starting from page 2.

$text = 'Testing 123';
$docx->addText($text);

 

Posted by admin  · 10-03-2016 - 08:03

Hello,

Yes, it's possible to do that. What version and license of phpdocx are you using?

Regards.

Posted by anjanesh  · 10-03-2016 - 08:11

Im currently using the trial. Will be buying the Enterprise version soon.

Posted by admin  · 10-03-2016 - 09:01

Hello,

You can do that setting the headers on the template or using the MultiMerge class (this is the easiest solution to accomplish what you need). The MultiMerge class is available only in Corporate and Enterprise licenses.

After you buy a license please contact us again and we'll send you an example to show how to do that.

Regards.

Posted by anjanesh  · 04-04-2016 - 06:55

I got this solved by :

$docx->replaceVariableByText($variables_header, ['target' => "header"]);

 

Posted by admin  · 04-04-2016 - 07:04

Hello,

That code doesn't add a header starting from page 2, it just replaces the existing placeholders in headers. To add a header starting from page 2 you need to use the MultiMerge class available in Corporate and Enterprise licenses.

Regards.