Conversion plugin phpdocx

Other conversion methods

Other conversion methods

Besides the conversion plugin, phpdocx has many other methods to transform documents between formats.

This method allows to convert a DOCX to TXT:

You can transform the whole content or exclude parts like tables, footnotes or endnotes.

This method exports the body of the document only, without headers or footers. The available parameters are:

  • $from: Sets the original file
  • $to: Sets the destination file
  • $options: It's an array of options to export all content or just some specifics parts of it

For example, to export the file test.docx with paragraphs, lists, tables, footnotes and endnotes, and omit the graphic charts, type this code:

The second available method is txt2docx. This is the opposite of docx2txt. It creates a DOCX file from a TXT. It's very easy to use: just call the method stating the txt to transform:

Then generate the new document:

Finally, apply the method transformDocxUsingMSWord.

To run this method you need a Windows server with the latest MS Office version and a web server with PHP support with the COM functions enabled.

Type this code to do the conversion:

Due to the special behavior of the COM functions, it is advisable to write absolute paths for the origin and destination folders, with double slashes. For example:

Next - Common problems and possible errors