Phpword: TemplateProcessor insert PageBreak possible?

Created on 22 Jun 2017  路  6Comments  路  Source: PHPOffice/PHPWord

Hi
ist it possible to insert a pagebreak inside a processed document?

thanks!
Alex

Responded Template Processor

Most helpful comment

I've found your solution working also on OpenOffice.

First you need to close previous text tag and reopen new row in the same paragraph with page break:
$templateProcessor->setValue('PAGE_BREAK', ''.''
. '');

All 6 comments

Can you try the following?

in you word document, put

${pageBreakHere}

Then run:

Settings::setOutputEscapingEnabled(false); //important, otherwise the XML will be written as is in the word document
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/template.docx');
$templateProcessor->setValue('pageBreakHere', '<w:p><w:r><w:br w:type="page"/></w:r></w:p>');
$templateProcessor->saveAs('results/generated_templateFile.docx');

This is not working for me. Can anyone confirm that it is working?

@SalvatorePollaci this worked for me.
PHP 7.0
phpoffice/phpword current (dev-master)

It's only working when opening on Word, not LibreOffice...
May be using xml is simplier than using the library...

I've found your solution working also on OpenOffice.

First you need to close previous text tag and reopen new row in the same paragraph with page break:
$templateProcessor->setValue('PAGE_BREAK', ''.''
. '');

Not worked for me please can you share with more detail

getting error with [ Settings::setOutputEscapingEnabled(false); ] this line

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igorsantos07 picture igorsantos07  路  3Comments

jaberu picture jaberu  路  3Comments

tasmer picture tasmer  路  3Comments

dwalker109 picture dwalker109  路  6Comments

carlosvr90 picture carlosvr90  路  4Comments