Conversion plugin phpdocx

Running the first example and available options

Running the first example

You can transform documents with the transformDocument method or directly calling the transformation classes.

This would be an easy example to create a DOCX and convert it to PDF:

Or to transform an existing DOCX:

The method to use in both examples is the one defined in the configuration file config/phpdocxconfig.ini.

Available options

The transformDocument method has some parameters which you may have to customize.

Here's the signature of the method:

These are the available parameters:

source

Path to the DOCX that you want to convert to a different format.

target

Path to the resulting transformed document (PDF, HTML, XHTML, DOCX, DOC, ODT, RTF, PNG or TXT).

method

Method used to transform the document: 'native', 'libreoffice', 'msword', 'openoffice'.

'native' method options

The possible keys and values are:

Key Type Description
dompdf DOMPDF dompdf instance.
stream bool False as default. If true, returns the document as stream.

'libreoffice' method options

The possible keys and values are:

Key Type Description
comments bool False by default. Export comments
debug bool False by default. Returns debug information about the conversion plugin.
escapeshellarg bool False by default. Applies escapeshellarg to escape the source string.
extraOptions string Extra parameters to be used when doing the conversion.
formsfields bool False by default. Export form fields.
lossless bool False by default. Lossless compression.
homeFolder string Set a custom home folder to be used for the conversions.
outdir string Set the outdir path. Useful when the PDF output path is not the same than the running script.
pdfa1 bool False by default. Generate PDF/A-1 document.
pdfa2 bool False by default. Generate PDF/A-2 document.
pdfa3 bool False by default. Generate PDF/A-3 document.
toc bool False by default. If true updates the TOC before transforming the document.

'msword' method options

The possible keys and values are:

Key Type Description
selectedContent string Scope: 'active' (default) or 'documents'.
toc bool False by default. If true updates the TOC before transforming the document.

'openoffice' method options

The possible keys and values are:

Key Type Description
debug bool False by default. Returns debug information about the conversion plugin.
homeFolder string Set a custom home folder to be used for the conversions.
odfconverter bool True by default. If set to false the conversion plugin does not use ODFConverter package. This may give better results in some cases.
tempDir string Set a custom temp folder to be used for the conversions.
version string 32-bit or 64-bit architecture. 32, 64 or null (default). If null autodetect.
Transformation classes

If you don't need to generate a new document and you just need to make the conversion, you can directly instantiate the following classes:

  • TransformDocAdvLibreOffice, for LibreOffice
  • TransformDocAdvNative, for native PHP classes
  • TransformDocAdvMSWord, for MS Word
  • TransformDocAdvOpenOffice, for OpenOffice

Working with these classes is as simple as including the autoloader:

Then instantiate an object with the desired class:

For LibreOffice:

for native PHP classes:

for MS Word:

or for OpenOffice:

And then call the transformation:

The transformation classes don't have a method option in transformDocument.

Next - Preparing the documents for their conversion