Docx4j: Convert to PDF deprecated

gexicide picture gexicide · Dec 30, 2013 · Viewed 26.6k times · Source

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.

Answer

Fred Porciúncula picture Fred Porciúncula · Mar 31, 2016

This is how you do it:

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