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

Table of contents numbers missing #707

Closed
kemar-stpatrick876 opened this issue Jan 20, 2016 · 28 comments
Closed

Table of contents numbers missing #707

kemar-stpatrick876 opened this issue Jan 20, 2016 · 28 comments

Comments

@kemar-stpatrick876
Copy link

kemar-stpatrick876 commented Jan 20, 2016

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.

@ramiro174
Copy link

me to

@geoff-maddock
Copy link

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.

@v-man
Copy link

v-man commented Mar 7, 2016

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

@danyamasadeh
Copy link

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

@arrabal
Copy link

arrabal commented Jun 20, 2016

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

@Worst45
Copy link

Worst45 commented Aug 17, 2016

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

@sianto1997
Copy link

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.

@plusDao
Copy link

plusDao commented Dec 22, 2016

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

@scalco19
Copy link

Someone was able to put page numbers in TOC?

@Venkatasivareddyavula
Copy link

Can any one find solution for this?

@yjfvictor
Copy link

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

@rramirezbrown
Copy link

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

@troosan
Copy link
Contributor

troosan commented Nov 22, 2017

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.

@troosan
Copy link
Contributor

troosan commented Dec 25, 2017

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

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

@troosan troosan closed this as completed Dec 25, 2017
@fgali
Copy link

fgali commented Dec 27, 2017

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

@troosan
Copy link
Contributor

troosan commented Dec 27, 2017

@fgali in the samples
Sample_17_TitleTOC.php

@fgali
Copy link

fgali commented Dec 29, 2017

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.

@fgali
Copy link

fgali commented Dec 29, 2017

Any suggestions? troosan.

@troosan
Copy link
Contributor

troosan commented Dec 29, 2017

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

@yangdevt
Copy link

yangdevt commented Jan 3, 2018

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

@HuPengCheng1994
Copy link

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

@chaitanyagubbala
Copy link

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

@ttde1
Copy link

ttde1 commented Jul 4, 2019

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

@yoedusvany
Copy link

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

@larryb-redflare
Copy link

@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.

@zhaomengxue7
Copy link

@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.

I have exactly the same problem , Has it been solved

@HuPengCheng1994
Copy link

HuPengCheng1994 commented Sep 7, 2021 via email

@zhaomengxue7
Copy link

You can try the following two ways to solve it
1、 Set windows file Security
2、 Generate files into a compressed package, It can be displayed normally after decompression

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

No branches or pull requests