Conversion plugin phpdocx

Common problems and possible errors

Tip

phpdocx includes the check-conversionplugin.php script to automatically detect the most common issues during the conversion plugin setup, with suggestions of solutions for them.

Common problems and issues
  • altChunk tag: The addExternalFile and replaceVariableByExternalFile methods use the Word altChunk internal tag. This allows to insert external files in a Word document. This tag is supported only by the msword method of the conversion plugin.
  • TOC generation: the TOC generation when transforming to PDF is supported. Please check the included documentation in the Advanced and Premium packages to generate the TOC when transforming the documents.
  • Font families: To generate PDFs with the same fonts as the original document you need those fonts installed in your operating systems. All operating systems allow to install them easily. See the Cookbook entry on good practices about fonts for more information.
  • Links don't work in the PDF: LibreOffice requires adding an existing custom character style to hyperlink tags. By default, phpdocx adds DefaultParagraphFontPHPDOCX to hyperlink tags. Custom character styles (such as Hyperlink) can be used with addLink and HTML methods.
  • Avoid using special shell characters such as spaces, percent sings 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.
LibreOffice Linux common problems and issues
  • .config directory: LibreOffice needs permissions to read and write in the .config directory on the PHP HOME. You can obtain it with this line of code:

    If this directory doesn't exist you have to create it with rwx permissions for the LibreOffice user or set 777 access.

    If you get an empty value as home folder, you can change the PHP configuration to set a custom one, or set a value dynamically using phpdocx. For example, to set /home/web as HOME folder:

  • Error rename: If you get an error quite similar to rename(tmp/document.pdf,tmp/output.pdf) when you try the conversion and actually get the DOCX you wanted to create. That error is due to the impossibility of converting the document through LibreOffice. See Debugging LibreOffice for more information.
  • CentOS: If you work with CentOS and install the LibreOffice packages from the official repositories, it is mandatory to install the libreoffice-headless package to run the conversion plugin.
  • Opened LibreOffice: To work in headless mode and perform all conversions it is mandatory to close LibreOffice. If you have any LibreOffice window open, close all of them before doing the transformations.
  • SELinux: If you're working with SELinux you need to disable it or put the process type or SELinux into permissive mode by using setenforce or semanage commands.
  • Concurrent conversions: To transform multiple documents at the same time and generate all outputs correctly, multiple folders must be used as home path. The best solution is using a random path of the home folder:

    Or using extraOptions:

LibreOffice Windows common problems and issues
  • phpdocx set up file: If the path to LibreOffice in the config/phpdocxconfig.ini file contains spaces, you have to wrap it between single quotation marks, e.g.:
  • IIS web server: To convert files properly with this web server you have to grant rw access to the IIS user (IUSR and IIS_IUSRS as default) for the target directory, and then check the following set up PHP line:
  • Temp folder for the conversions: When using IIS web server, a temp folder must be set using the extraOptions option. For example, to use C:\Windows\Temp\LibreOffice as temp folder:
    This temp folder must exists with the correct permissions.
  • Error rename: The rename PHP method may show an error quite similar to rename(tmp/document.pdf,tmp/output.pdf) when you try the conversion and actually get the DOCX you wanted to create. That error is due to the impossibility of converting the document through LibreOffice. See Debugging OpenOffice and Debugging LibreOffice for more information.
  • Opened LibreOffice: To work in headless mode and perform all conversions it is mandatory to close LibreOffice. If you have any LibreOffice window open, close all of them before doing the transformations.
  • Concurrent conversions: Please check the same question in the LibreOffice Linux common problems and issues section.
MS Word common problems and issues
  • Error using the active document: if the transformation returns an error related to unable to open the DOCX, the msword method allows to choose documents or active as selected content. The default value is active, if it fails documents must be chosen.
  • dcom config should be configured to allow "interactive user", "remote access" and "remote action", as well as adding the "IUSR" account.
  • Source and target files must use absolute paths and double backslashes: 'C:\\folder\\source.docx' .
Native common problems and issues
  • Use a new instance of DOMPDF for each transformation.
OpenOffice Linux common problems and issues
  • temporary directory: If you run OpenOffice along with OdfConverter, it is necessary to create a temporary ODT document.
    To create the ODT it is mandatory to have read and write permissions in a temporary directory. If you can't use the OS temp folder, the transformDocument method allows to set a new one.
  • .wapi directory: For proper functioning with a web server like Apache, you must create a .wapi directory in the root of the HOME folder.
    An example could be /var/www/.wapi, with read and write permissions for the corresponding user.
    The absence and need of this directory, and the path where it has to be located, is generated in the log files of the web server you use.
  • wrong version of libtiff: If the conversion returns an error message related to the version of the libtiff library, you can create a symbolic link to solve it.
    For example, if you have libtiff.so.4 running and you get an error related to libtiff.so.3, write the following lines:
Next - Debugging LibreOffice