所需的jar:
jaxb-impl 2.1
avalon-framework-4.1.5
commons-io-2.4
docx4j-2.7.1
log4j-1.2.15
serializer-2.7.1
xmlgraphics-commons-1.3
batik-util-1.6-1
commons-logging-1.1.3
fop-0.93
xalan-2.7.1
public static void main(String[] args) {
try {
long start = System.currentTimeMillis();
InputStream is = new FileInputStream(new File("D:\test.doc"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
Mapper fontMapper = new IdentityPlusMapper();
PhysicalFont font = PhysicalFonts.getPhysicalFonts().get("Arial Unicode MS");
fontMapper.getFontMappings().put("Algerian", font);
wordMLPackage.setFontMapper(fontMapper);
PdfSettings pdfSettings = new PdfSettings();
org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
wordMLPackage);
//注释生成pdf 默认的内容
org.docx4j.convert.out.pdf.viaXSLFO.Conversion.log.setLevel(Level.OFF);
OutputStream out = new FileOutputStream(new File("D:\javadomain.pdf"));
conversion.output(out, pdfSettings);
System.err.println("Time taken to Generate pdf " + (System.currentTimeMillis() - start) + "ms");
} catch (Exception e) {
e.printStackTrace();
}
}