Forum


Replies: 6   Views: 1877
Toc never generated after merge
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by FinCalc  · 11-05-2020 - 10:20

I am building up a word document using templates, I never know how many of the same template will be added to the final document it depends as it is data driven. This is all working fine however no matter which way I try to add the table of contents in at the end whether it be merged in etc it will not display the headings in the document. If I manually click update TOC in the finished document they all display correctly.

Any help would be appreciated.  

Posted by admin  · 11-05-2020 - 10:34

Hello,

Please check the documentation available on https://www.phpdocx.com/documentation/cookbook/tables-of-contents (It is possible to update the TOC automatically when opening the document? section). Due to internal restrictions, MS Word doesn't allow updating automatically a DOCX when the document is opened.

If you need to update the TOC automatically, you need to use a macro or the conversion plugin with the libreoffice or msword methods:

https://www.phpdocx.com/documentation/cookbook/tables-of-contents (Generate the TOC automatically with the conversion plugin section).

About the conversion plugin, please check the documentation available on the following pages:

https://www.phpdocx.com/documentation/conversion-plugin

https://www.phpdocx.com/api-documentation/format-conversion/convert-Word-docx-into-pdf-with-PHP

To use the conversion plugin based on libreoffice and autogenerate the TOC please check the docs folder available in the package.

Regards.

Posted by FinCalc  · 11-05-2020 - 10:45

Thank you for the fast response however we have tried the following code which takes the final output document with TOC but which does not get updated : 

 $phpdocx->transformDocument($_SERVER['DOCUMENT_ROOT'] . '/pdf/output.docx', $_SERVER['DOCUMENT_ROOT'] . '/pdf/output.docx', null, array('toc' => true));

 

Any help appreciated. 

Posted by FinCalc  · 11-05-2020 - 10:48

We have also tried to add a brand new TOC into the finished document using a word fragment but this was blank. Any ideas?

Posted by admin  · 11-05-2020 - 11:03

Hello,

If you are using the conversion plugin based on libreoffice, did you install and enable the macro as the documentation in the docs folder details? Please follow the steps explained on https://www.phpdocx.com/documentation/conversion-plugin/debugging-libreoffice to debug the conversion plugin based on LibreOffice.

About the other question, TOC can be added as WordFragment to documents created from scratch or to templates. Please check the included sample examples/Core/addTableContents/sample_2.php that details adding a TOC as WordFragment to a DOCX.

Regards.

Posted by FinCalc  · 11-05-2020 - 11:08

Will have a look and post our findings. If using "native" and trying to convert to PDF we get the following error: 

Type: Error

Message: Call to undefined method DOMText::getElementsByTagNameNS()

Filename:..\phpdocx\classes\TransformDocAdvPDF.php

Line Number: 2179

Posted by admin  · 11-05-2020 - 11:16

Hello,

The native conversion doesn't update the TOC. Please check the information explained in a previous reply:

If you need to update the TOC automatically, you need to use a macro or the conversion plugin with the libreoffice or msword methods...

The native conversion supports a set of contents and styles (https://www.phpdocx.com/documentation/conversion-plugin/preparing-the-templates-for-its-conversion Supported OOXML tags and attributes when using the native method section). The DOCX you are trying to transform must be used some not supported content, please use the conversion plugin based on libreoffice or msword.

Regards.