transformDocument

transformDocument

ADVANCED / PREMIUM BASIC

Transforms documents into other formats (DOCX, PDF, HTML, XHTML, DOC, RTF, PNG, TXT).

Description
public transformDocument (string $source, string $target [, string $tempDir [, array $options]])

This method allows to transform a DOCX document, generated or not with phpdocx, into PDF, HTML, DOC, ODT, RTF, PNG and TXT preserving, as much as possible, the original formatting options.

It can also transforms DOC, ODT and RTF to DOCX.

You may find more info regarding this method in the Conversion plugin section.

Due to format limitations, the PNG transformation only generates the first page of the document.

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).

options

The possible keys and values are:

Key Type Description
method string It may take the following values:
  • 'direct': Default value.
  • 'script': It may solve certain problems with Apache in some installations.
odfconverter bool Only used by OpenOffice. True by default. If set to false the conversion plugin does not use ODFConverter package. This may give better results in some cases.
debug bool False by default. It shows debug information about the conversion plugin.
Return values

Void.

Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like: