Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateProcessor insert PageBreak possible? #1082

Closed
alexmilde opened this issue Jun 22, 2017 · 7 comments
Closed

TemplateProcessor insert PageBreak possible? #1082

alexmilde opened this issue Jun 22, 2017 · 7 comments

Comments

@alexmilde
Copy link

alexmilde commented Jun 22, 2017

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

thanks!
Alex

@troosan
Copy link
Contributor

troosan commented Jun 26, 2017

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

@SalvatorePollaci
Copy link

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

@NickCoolii
Copy link

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

@Bluestart83
Copy link

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

@Bluestart83
Copy link

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', '</w:t></w:r>'.'<w:r><w:br w:type="page"/></w:r>'
. '<w:r><w:t>');

@gautamkoshiya
Copy link

gautamkoshiya commented Apr 30, 2020

Not worked for me please can you share with more detail

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

@MikeStrike94
Copy link

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', '</w:t></w:r>'.'<w:r><w:br w:type="page"/></w:r>' . '<w:r><w:t>');

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants