Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docx4j: Convert to PDF deprecated

Tags:

pdf

docx4j

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.

like image 870
gexicide Avatar asked Dec 30 '13 12:12

gexicide


2 Answers

This is how you do it:

Docx4J.toPDF(wordMLPackage, new FileOutputStream("path/to/your-pdf-file.pdf"));
like image 180
Fred Porciúncula Avatar answered Sep 18 '22 14:09

Fred Porciúncula


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

like image 25
JasonPlutext Avatar answered Sep 20 '22 14:09

JasonPlutext