Phpword: Table of contents numbers missing

Created on 20 Jan 2016  路  25Comments  路  Source: PHPOffice/PHPWord

I have an issue where my TOC is being generated without the page numbers,

image

can someone help me with this, thanks in advance


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Most helpful comment

Unable to display page number even after setUpdateFields set to true.

All 25 comments

me to

It's going to take somebody taking on the issue, because it doesn't seem like any of the previous developers are following up on these issues. I'm going to see if I can't figure it out soon.

Is there any update for the page numbers missing issue of TOC? I encounter the similar problem like the following attachment show by v0.12.1. Thanks a lot.
66ee tmp

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

Still waiting for updates on this issue. It would be great to have numbers in the TOC

+1, still waiting too (in v0.13.0) :)

Can't you implement a loop at the end of the document which detects on which pages the titles are, and then add those page numbers to the TOC? I'll try it myself, and if it works I will post it here.

in fact, it's a little effect. Toc will arraise page number after print it as paper

Someone was able to put page numbers in TOC?

Can any one find solution for this?

This issue has been open for one year and a half. Is there anybody going to solve this problem?

Hello, I've experienced the same issues, does anybody know if it has been solved?

can anybody post a code sample of the issue?
What's sure is that we cannot set the page number as we do not know it when building the document. What you can do is once you open the document, update the fields. Word will then recompute the page numbers.

what you can do to force word to recompute all fields is set updateFields to true

$phpWord->getSettings()->setUpdateFields(true);

Where can I get an example code on how to make a table of contents?

@fgali in the samples
Sample_17_TitleTOC.php

The solution you give for the toc numbers is useful for me when I am on my local server on windows but not when I upload it to the hoting.

Any suggestions? troosan.

I fail to see the difference between your local server and your remote hosting.
Care to elaborate?

addTOC is being generated without the page numbers still,
Is this solved?

$phpWord->getSettings()->setUpdateFields(true);

Unable to display page number even after setUpdateFields set to true.

We麓ve been able to reproduce and fix this issue.
You have to active the
$phpWord->getSettings()->setUpdateFields(true);
configuration and please replace the following file, with the file attached.

While the MacOS Word is able to reference to a page number using the element麓s name, the Windows Word is only able to load the very page number using the element麓s id.

File location:
/phpword/phpoffice/phpword/src/PhpWord/Writer/Word2007/Element/TOC.php

TOC.php.zip

Hi, I replaced the file, but I have the issue yet.

@troosan

I fail to see the difference between your local server and your remote hosting.
Care to elaborate?

The issue (and still occurring in 2019) is if you generate the file with PHP locally and open from a local disk it prompts you to update the file when you open. Generate the file from a web hosted page and when the file opens, Word displays a protected message saying are you sure you want to trust people on the internet, and even when you say yes i trust people on the internet and it allows you to edit the file, the prompt on open that occurs for locally generated files, does not happen and so the TOC remains with no page numbers, requiring a manual update.

I believe the problem is
2019-09-26 21_18_50-CustomRiskReport (14) docx  -  Protected View - Word

I also don't think there is a way to fix in PHPWord, as essentially you would need to set a flag - saying trust me, I'm a good actor on the internet and so running a "macro" is safe; but clearly if PHPWord provided just such a flag, how would we know some bad people would not also set the flag?

So the fix works for files served from trusted locations, but files from untrusted locations do not auto update on open.

Was this page helpful?
0 / 5 - 0 ratings