pdx:transformDocument

Transforms .docx documents into another formats (.pdf, .doc, .rtf, .html).

Description

Element definition

x
 
1
<pdx:config>
2
    <pdx:transformDocument pdx:src="" pdx:target="" pdx:comments="" pdx:formsfields="" pdx:homeFolder="" pdx:lossless="" pdx:pdfa1="" pdx:toc="" />
3
</pdx:config>
4

This element allows to transform a docx, generated or not with xmldocx, into PDF, DOC, RTF, ODF or HTML preserving, as much as possible, the original formatting options.

You may find more info regarding this element in the Conversion plugin help section and in our Tutorial.

This method uses OpenOffice or LibreOffice to transform the documents. It is compatible with Linux, Windows and macOS and offers perfect results in most of the cases, but in some templates it will be required to perform small changes to get a satisfactory output.

Attributes and sub-elements

src

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

target

Path to the resulting transformed document (.pdf, .doc, .rtf, .odf or .html).

comments

Export comments.

formsfields

Export form fields.

homeFolder

Set a custom home folder when doing the transformation.

pdfa1

Export as PDF/A-1

toc

Generate and export TOC.

Code samples
#Example 1

config.xml

8
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:config>
4
        <pdx:output pdx:name="output" pdx:type="pdf" />
5
        <pdx:transformDocument pdx:src="/var/www/xmldocx/samples/files/Text.docx" pdx:target="/var/www/xmldocx/samples/FormatConversion/transformDocument/Text.pdf" />
6
    </pdx:config>
7
</pdx:document>
8

content.xml

6
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:content>
4
    </pdx:content>
5
</pdx:document>
6

settings.xml

6
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:settings>
4
    </pdx:settings>
5
</pdx:document>
6
10
 
1
import os as os
2
import sys as sys
3
sys.path.append(os.path.abspath("wrappers/python/XmlDocx"))
4
import XmlDocx as XmlDocx
5
document = XmlDocx.XmlDocx("config.xml")
6
document.setDocumentProperties("settings.xml")
7
document.addContent("content.xml")
8
document.setXmlDocxPath("xmldocx path")
9
document.render()
10

The resulting Pdf document looks like: