Forum


Replies: 3   Views: 1938
Generating toc before save
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 Encaster  · 22-06-2020 - 13:07

Hi! I'm using adv license and i got problem. I need to generate TOC before save with native method. Is it possible? Msword method is not available on my linux server.
PS. if i try to transform from docx to docx with native method, nothing happens. 
The code generates test.docx correctly, then creates test2.pdf. But not creates test2.docx. Can you explain why?
 

$docx->createDocx('test.docx');
$docx->transformDocument('test.docx', 'test2.pdf');
$docx->transformDocument('test.docx', 'test2.docx');

Posted by admin  · 22-06-2020 - 14:08

Hello,

Generating TOC is only available using libreoffice and msword methods, the native method doesn't support it. You can read this information on the following documentation page:

https://www.phpdocx.com/api-documentation/format-conversion/convert-Word-docx-into-pdf-with-PHP (Parameters section - toc option)

Working with a Linux server, we recommend using the conversion plugin based on LibreOffice. Please check the docs folder included in the package to understand how to generate TOC contents when transforming to PDF/DOCX, get PDF A-1 files and other options available in transformDocument when using libreoffice.

Regards.

Posted by Encaster  · 26-06-2020 - 11:40

i've installed last version of libreoffice in ubuntu. 
If i try to convert from docx to pdf /usr/bin/soffice --invisible --convert-to pdf test.doc it works fine, but i got no TOC in result file. Also i try to convert using PHP:

$docx->transformDocument(storage_path('app/temp_docx/test.docx'), storage_path('app/temp_docx/test2.pdf'), 'libreoffice', array('toc' => true));

It also works, but there is no TOC in PDF. What is the reason?
I tried like this, to be sure, that php is using libreoffice method:

$docxConvert = new TransformDocAdvLibreOffice();
$docxConvert->transformDocument(storage_path('app/temp_docx/test.docx'), storage_path('app/temp_docx/test2.pdf'), array('toc' => 'true'));

No TOC there. 
Any suggestions? 
I also tried to convert like this
/usr/bin/soffice --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --nofirststartwizard --convert-to pdf /var/www/application/storage/app/temp_docx/test.docx (same result)

So how can i get TOC in converted file?
And one more question. Is it possible to convert with libreoffice from DOCX to DOCX ( to get TOC before save) ?
I tried to do it in cli, but got error:
root@c3142a888a46:/var/www/html# /usr/bin/soffice --invisible --convert-to docx test.docx
convert /var/www/html/test.docx -> /var/www/html/test.docx using filter : MS Word 2007 XML
Overwriting: /var/www/html/test.docx
Error: Please verify input parameters... (SfxBaseModel::impl_store <file:///var/www/html/test.docx> failed: 0x4c0c(Error Area:Sfx Class:Write Code:12))
 

Posted by admin  · 26-06-2020 - 11:51

Hello,

Please check the docs folder included in the package to understand how to generate TOC contents when transforming to PDF/DOCX, get PDF A-1 files and other options available in transformDocument when using libreoffice. This feature is fully tested and working on Windows, Linux and macOS. As explained in the previous documentation you need to add a macro to your installation of LibreOffice to be able to generate the TOC (this macro needs to be added one time and it will used in all conversions that TOC are generated). Also note that the TOC content must exist, the following command:

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

update an existing TOC, but it doesn't add it. If you need to add a TOC dynamically you can use addTableContents.

You can generate TOC when transforming DOCX to PDF or to other document formats, including DOCX, but you can't use the same values as source and target. Also please check you are using a version of LibreOffice that supports saving as DOCX (LibreOffice 5.4 or newer, but we recommend using the latest release on libreoffice.org), using an old version of LibreOffice saving to DOCX isn't supported.

For further support, please send to contact[at]phpdocx.com the username or e-mail of the user that purchased the license and the DOCX you are using so we can check it.

Regards.