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 the changes the conversion plugin supports:

Source Output
DOCX PDF HTML DOC ODT PNG RTF TXT
DOC DOCX PDF HTML ODT PNG RTF TXT
ODT DOCX PDF HTML DOC PNG RTF TXT
RTF DOCX PDF 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.

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: