2

I would like to have the number of pages of my document in a template processed by phpWord.

I tried to do it with the following code :

In my template I have "the number of pages is ${total_pages}$

And I tried the following php code :

    $pages_text = new TextRun();
    $pages_text->addField('NUMPAGES');
    $processor->setComplexValue('total_pages',$pages_text);

Problem is it always prints 1 as a number of page. So i have "the number of page is 1" even if my template has 4 pages.

Could you help me with that ?

Thank you

1 Answer 1

0

Have you tried preserveText? Might be simpler.

$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.');

You can also use {SECTIONPAGES}. You can't add preserve text into a text run, however, so it must be used just like the addText method.

Sign up to request clarification or add additional context in comments.

2 Comments

The problem is that I am using a template, so the only way I have to replace a variable is with a textrun object ...
@PierreFtn I have the same problem, do we have any solution of this issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.