Forum


Replies: 2   Views: 4599
Error converting 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 rstoeber  · 01-07-2018 - 20:32

Running PHP 7.0 on Ubuntu 16.04 and LibreOffice 5.1.6.2

New version of phpdocx 8.2 (Advanced) installed today.

phpdocx config file is modified to use libreoffice like so:

[transform]
method = "libreoffice"

; libreoffice installation path, absolute path
path = "/usr/bin/soffice"
 

Creating docx files directly and from templates (with modifications) works perfectly.

When I try to convert any docx file to pdf I get errors. From the documentation and forums it looks like the recommended code is like this:

$docx = new TransformDocAdvLibreOffice();

$docx->transformDocument($docxname, $pdfname);

But that generates this error:

PHP Fatal error:  Uncaught Exception: The chosen extension is not supported 

I have no idea what that means. What extension isn't supported?

If I remove the phpdocx code and instead do it myself, this works perfectly:

exec("/usr/bin/soffice --headless --convert-to pdf:writer_pdf_Export --outdir $pdfname $docxname");

I thought it would be easier/safer/more reliable to use the docx-pdf conversion function in phpdocx, but I can't get it working. I even tried following the instructions in the website section called Debugging LibreOffice. That tells me to run a sample script called sample_1.php but that doesn't provide anything helpful. That script just generates a different error:

PHP Warning:  rename(./example_text.pdf,example_text.pdf): No such file or directory in /var/www/staging-wgaccounts/phpdocx/classes/TransformDocAdvLibreOffice.php on line 138

Any advice?


 

Posted by admin  · 01-07-2018 - 20:59

Hello,

That exception:

PHP Fatal error:  Uncaught Exception: The chosen extension is not supported

appears when the file extension isn't one of the allowed extensions:

$this->_allowedExtensions = array('docx', 'pdf', 'odt', 'sxw', 'rtf', 'doc', 'txt', 'html', 'htm', 'wiki', 'png');

Maybe you are using uppercase file extensions?

To test the conversion plugin, please run the included sample in the examples/FormatConversion/transformDocument folder using PHP CLI mode.

If you send to contact[at]phpdocx.com SSH access to your server and the path to phpdocx, the dev team will check it.

Regards.

Posted by rstoeber  · 01-07-2018 - 22:59

Thanks, I can't believe it was that obvious.

I had moved some file renaming code incorrectly. Now it works. Thank you.