Forum


Replies: 1   Views: 75
Transform to pdf with libreoffice in windows when paths include blank spaces

Posted by galileogali  · 22-12-2024 - 00:58

Hi guys

My dev environment is running on Windows and many of the paths are long paths. Default configuration on PDF transformer using LibreOffice didn't work. I've spent many hours to figure out the reason.

It turned out I've got long paths having a space in them (such as C:\Program Files\...). This brakes the passthru() calls in TransformDocAdvLibreOffice.php.

The sollution - if dealing with long names in Windows, all paths to executables and input/output dirs must be enclosed in double quotation marks.

Is it possible you will fix this?

 

Thanks

Radek

Posted by admin  · 22-12-2024 - 11:11

Hello,

Using a Windows server, if the path to LibreOffice contains spaces, you need to wrap it between single quotation marks in the config/phpdocxconfig.ini file, as detailed on (https://www.phpdocx.com/documentation/conversion-plugin/common-problems-and-possible-errors):

path = '"C:\Program Files (x86)\LibreOffice 5\program\soffice.exe"'

Also please note that since the release of phpdocx 14.5, a new escapeshellarg option was included in the conversion plugin based on LibreOffice:

escapeshellarg    bool    False by default. Applies escapeshellarg to escape the source string.

You can enable it to escape the source path.
This same option is explained on https://www.phpdocx.com/documentation/conversion-plugin/common-problems-and-possible-errors:

Avoid using special shell characters such as spaces, percent signs or exclamation marks in the input source when using the conversion plugins based on LibreOffice or MS Word. The conversion plugin based on LibreOffice includes the escapeshellarg option to escape the source string.

You can also use escapeshellarg (https://www.php.net/manual/en/function.escapeshellarg.php) from PHP to escape the paths when calling transformDocument.

Regards.