Forum


Replies: 4   Views: 3074
Toc update fails when transform docx to pdf
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 kratpic  · 08-05-2018 - 13:28

Here is my code :

$docx = new Phpdocx\Create\CreateDocx();

$docx->enableCompatibilityMode();

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
    'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' .
    'officia deserunt mollit anim id est laborum.';

$paramsText = array(
    'b' => 'single',
    'font' => 'Arial'
);

$docx->addText($text, $paramsText);

$docx->addTableContents(array('autoUpdate' => true,"displayLevels" => "1-2")); // add some headings so they show up in the TOC

$docx->createDocx('example_text');

$docx->transformDocument('example_text.docx', 'example_text.pdf', null, array('toc' => true));

With 

$docx->transformDocument('example_text.docx', 'example_text.pdf', null, array('toc' => false));

the PDF is created, but the TOC is not updated.

With 'toc' => true, the conversion fails

I need your help plese. Is-it a bug with version 8 ?

 

Posted by admin  · 08-05-2018 - 13:53

Hello,

No, there's no known bug in phpdocx 8. About your question, we have checked the conversion from DOCX to PDF is working perfectly, please read the documentation available in your package in the docs folder.

The files available in this folder explain how to autogenerate the TOC. You need to add a macro to the conversion plugin (available in the same folder) and then set 'toc' as true.

Regards.

Posted by kratpic  · 08-05-2018 - 14:57

Thank you. It works. I thought that with version 8, we didn't need macro anymore for updating toc. It was my fault.

Posted by kratpic  · 16-05-2018 - 15:04

I still have a problem with TOC but this time on Linux (it's ok on Windows my dev platform)

On Linux, conversion to PDF is ok without TOC, but it doesn't work with the TOC. I think the problem is still with the macro. Here is what I've done :

- I have made a pdf conversion in LibreOffice with my user
- I updated "Module1.xba" for my user.
- I copied ".config/libreoffice" (all directory) from my user to www-data user

But it still doesn't work...

Thank for your help

Posted by admin  · 17-05-2018 - 06:36

Hllo,

Instead of copying the files from one user to other (maybe some rw permission is missing?), we recommend you to clean that folder and regenerate it again using the web server user, then follow the steps explained in the docs folder of the package, copy the macro and run the conversion using this line:

$docx->transformDocument('example_text.docx', 'example_text.pdf', null, array('toc' => true));

The TOC will be generated correcty. If you send to contact[at]phpdocx.com SSH access, the path where phpdocx is installed and an URL to test it using a web browser we'll check it.

Regards.