Forum


Replies: 5   Views: 6693
Pdf conversion
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 dealcloser  · 10-04-2017 - 00:19

Hello,

We've recently purchased 2 Premium licenses, but we're unable to get the PDF conversion working. System specs are CentOS 7.3 / PHP 7 / Laravel 5.3 / OpenOffice 4.1.3 . Here is the basic code we're using:

use Phpdocx\Transform\TransformDocAdvOpenOffice;

$docx = new TransformDocAdvOpenOffice();
$docx->transformDocument('SampleAgreement.docx', 'SampleAgreement.pdf', null, array('debug' => true));

Below is output from Laravel's tinker:

$ php artisan tinker
Psy Shell v0.8.3 (PHP 7.0.14 — cli) by Justin Hileman
>>> use Phpdocx\Transform\TransformDocAdvOpenOffice;
=> null
>>> $docx = new TransformDocAdvOpenOffice();
=> Phpdocx\Transform\TransformDocAdvOpenOffice {#730}
>>> $docx->transformDocument('SampleAgreement.docx', 'SampleAgreement.pdf', null, array('debug' => true));
PHP error:  Undefined offset: 0 in vendor/phpdocx/Classes/Phpdocx/Parse/RepairPDF.inc on line 160
PHP error:  Undefined offset: 0 in vendor/phpdocx/Classes/Phpdocx/Parse/RepairPDF.inc on line 160
PHP error:  Undefined offset: 0 in vendor/phpdocx/Classes/Phpdocx/Parse/RepairPDF.inc on line 182

I've also tried running a test outside of Laravel with PHP CLI. The script is here:

require_once('Classes/Phpdocx/Create/CreateDocx.inc');

use Phpdocx\Transform\TransformDocAdvOpenOffice;

$docx = new TransformDocAdvOpenOffice();
$docx->transformDocument('SampleAgreement.docx', 'SampleAgreement.pdf', './', array('debug' => true));

The output from this script is as follows:

phpdocx/Classes/Phpdocx/Transform/../../../lib/OdfConverter/64/OdfConverter: error while loading shared libraries: libtiff.so.3: cannot open shared object file: No such file or directory
Apr 09, 2017 6:17:09 PM com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection connect
INFO: connected
Apr 09, 2017 6:17:09 PM com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection disposing
INFO: disconnected
Exception in thread "main" java.lang.IllegalArgumentException: inputFile doesn't exist: ./tempOdt_58eacf0596214.odt
        at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:90)
        at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74)
        at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70)
        at com.artofsolving.jodconverter.cli.ConvertDocument.convertOne(ConvertDocument.java:154)
        at com.artofsolving.jodconverter.cli.ConvertDocument.main(ConvertDocument.java:133)

These look like two different issues, but I'm not sure what's happening underneath the hood.

 

Posted by admin  · 10-04-2017 - 06:47

Hello,

To get the best output we reccomend you to use the conversion plugin based on LibreOffice:

https://www.phpdocx.com/documentation/conversion-plugin/conversion-plugin-installation-and-set-up

Please install the latest version of LibreOffice.

If you prefer to use the conversion plugin based on OpenOffice as you are doing now, you may need to install some missing libraries in your OS. The error you get is related to a missing library (error while loading shared libraries: libtiff.so.3), you need to install it using yum. As this version of libtiff may not be available in your OS, you can install the version available and then create a symbolic link.

There's quick guide about common problems and how to debug the conversion plugin on:

https://www.phpdocx.com/documentation/conversion-plugin/common-problems-and-possible-errors

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

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

Regards.

Posted by dealcloser  · 10-04-2017 - 14:21

I have LibreOffice working, but the phpdocx conversion still fails.

I can successfully convert a file using the LibreOffice utility:

$ /opt/libreoffice5.3/program/soffice --invisible --convert-to pdf SampleAgreement.docx 
convert SampleAgreement.docx -> SampleAgreement.pdf using filter : writer_pdf_Export

I updated config/phpdocxconfig.ini as follows:

; libreoffice or openoffice
method = "libreoffice"

; libreoffice installation path, absolute path
path = "/opt/libreoffice5.3/program/soffice"

I ran the test conversion again (outside of Laravel)

$ php test.php 
[INFO][phpdocx/tempDocX_58eb92c13f92d.docx] Converting tempDocX_58eb92c13f92d.docx into tempOdt_58eb92c140673.odt
progress:w:progress:w:t[INFO][phpdocx/tempDocX_58eb92c13f92d.docx] Conversion succeeded
[INFO][phpdocx/tempDocX_58eb92c13f92d.docx] Total conversion time: 00:00:00.7249124
Done.
ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port 8100.

Although it says the conversion succeeded, there is no PDF file output. It also says it's looking for OpenOffice running, but I have configured LibreOffice in the config file as above.

Posted by admin  · 10-04-2017 - 18:27

Hello,

We see in your script these lines:

use Phpdocx\Transform\TransformDocAdvOpenOffice;

$docx = new TransformDocAdvOpenOffice();

This script is not using the conversion plugin based on LibreOffice but the one based on OpenOffice.
As you can read on https://www.phpdocx.com/documentation/conversion-plugin/running-the-first-example-and-available-options, to use LibreOffice you need to use the TransformDocAdvLibreOffice class:

use Phpdocx\Transform\TransformDocAdvLibreOffice;

$docx = new TransformDocAdvLibreOffice();

or the transformDocument method to autodetect the conversion plugin automatically from the data of the config file.

After you have set the options in config/phpdocxconfig.ini, please try to run the included sample FormatConversion/transformDocument/sample_1.php using PHP CLI mode:

$ php sample_1.php

It must generate the PDF fine. 

If you send to contact[at]phpdocx.com SSH access to your server a member of the dev team can check it directly. We'd need SSH access, the path where phpdocx is installed and an URL to test it using a web browser.

Regards.

Posted by dealcloser  · 10-04-2017 - 19:17

Thank you for catching that! The conversion is working - thank you very much for your help.

Posted by admin  · 10-04-2017 - 19:21

Hello,

We are glad to hear it :). If you have any other issue or question do not hesitate to update this topic or open a new one.

Regards.