Cookbook

Transform document formats

The conversion plugin, available for the Advanced and Premium licenses, allows to transform document formats, e.g., from DOCX to PDF, HTML or PNG, from DOC to DOCX, from RTF to DOC, etcetera.

The following table shows all transformations the conversion plugin supports:

Source Output
DOCX PDF (X)HTML DOC ODT PNG RTF TXT
DOC DOCX PDF (X)HTML ODT PNG RTF TXT
ODT DOCX PDF (X)HTML DOC PNG RTF TXT
PDF DOCX DOC ODT RTF PNG TXT
RTF DOCX PDF (X)HTML DOC ODT PNG TXT

Note

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

You can complement the conversion plugin with two phpdocx methods: embedHTML to transform HTML to DOCX and TXT2DOCX to convert text files to DOCX.

These functionalities enable phpdocx to perform virtually any type of conversion.

phpdocx 8 and newer releases of Advanced and Premium licenses include native PHP classes to transform DOCX to HTML. The output can be viewed using a web browser or customized to fit the needs of any project. For more information, read DOCX to HTML.
phpdocx 9 and newer releases of Advanced and Premium licenses include native PHP classes to transform DOCX to PDF. For more information, read DOCX to PDF.

Doing the conversion

Once the conversion plugin is installed, the transformation from one document format to another is as simple as calling the transformDocument method.

For example, these lines of code convert DOCX to PDF...

...this one converts DOC to DOCX...

...and finally, these lines convert DOCX to PNG and HTML: