PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Is there any update for the page numbers missing issue of TOC ?

Open jiayuxiaochaoren opened this issue 6 years ago • 4 comments

I use the version 0.16.0,but still has this question.

jiayuxiaochaoren avatar Aug 13 '19 03:08 jiayuxiaochaoren

AFAIK just make sure to set $phpWord->getSettings()->setUpdateFields(true); and that the document is not in "protected" mode, and open the document in Word. A pop-up will open to ask you whether you want to update the document, agree. After Word updated the fields, the page numbers will display.

At the level of PHPWord, there is no way to know on which page the content will end up on, it is up to Word.

mdupont avatar Sep 03 '19 08:09 mdupont

Thank you for your reply. but I still don't understand, why i can get titles of contents but can't get the nums of pages?

jiayuxiaochaoren avatar Sep 03 '19 09:09 jiayuxiaochaoren

Any solution to this?

cerw avatar Sep 17 '21 00:09 cerw

I've found a possible solution: just change in PhpWord/Writer/Word2007/Element/TOC.php the line 116 from

$xmlWriter->text("PAGEREF _Toc{$rId} \\h");

to

$xmlWriter->text("PAGEREF $rId \\h");

using $phpWord->getSettings()->setUpdateFields(true); it seems it works.

jgiacomello avatar Jan 17 '24 09:01 jgiacomello