How to convert xsl-fo to docx (Office Open XML) in

2019-04-15 17:24发布

问题:

I'm looking for an open-source or commercial friendly library in Java to convert xsl-fo to docx (Office Open XML) format.

I'm planing to use xsl-fo to produce pdf documents (with Apache FOP), so I thought generating Word documents (docx) out of the same source XML could be a good idea.

UPDATE: I forgot to mention that I'm using Java.

回答1:

Alternatively, you could do: your source xml -> docx -> xsl-fo -> pdf.

or easier perhaps: source xml -> Flat OPC XML -> xsl-fo -> pdf.

Once you have a docx (or a Flat OPC XML document), transforming that to PDF via FOP is easy with docx4j (since you mention FOP, I'm assuming Java is ok for you).

The benefit of this approach is that you style your output docx as desired, and get the xsl fo "for free".

Flat OPC XML is convenient, because it is docx as a single XML file (ie no need to unzip). So you can create it easily via XSLT. To see it, create a document in Word 2007, and choose "save as .. xml".