Pregunta

The "getting started" document of docx4j contains sample code to write a docx to pdf:

// Set up converter
org.docx4j.convert.out.pdf.PdfConversion c = 
    new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);

However, as of docx4j 3.0, the whole PdfConversion facility seems to be deprecated without a notice how to perform the conversion now. So what is the non-deprecated way of transforming a docx to pdf with the docx4j 3.0.

¿Fue útil?

Solución 2

docx4j 3.0 has a facade you can use to convert to PDF.

There's an example of using it at

https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ConvertOutPDF.java

Otros consejos

This is how you do it:

Docx4J.toPDF(wordMLPackage, new FileOutputStream("path/to/your-pdf-file.pdf"));

Enough said... from the sample source code:

 * From v3.3.0, PDF output is by default via Plutext's commercial PDF Converter.
 * 
 * By default, the evaluation instance at:
 * 
 *      http://converter-eval.plutext.com:80/v1/00000000-0000-0000-0000-000000000000/convert
 *  
 * is used.  To specify your own instance, please set docx4j.properties property: 
 * 
 *      com.plutext.converter.URL=http://your.host:80/v1/00000000-0000-0000-0000-000000000000/convert
 * 
 * If you don't want to use Plutext's PDF Converter, you can still use XSL FO and Apache FOP;
 * just put docx4j-export-fo and its depedencies on your classpath and use Docx4J.toFO
 * as per the example below.

So what's the point of using Docx4J if you have to fall back to using XSL-FO/FOP...?!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top