docx4j将word 转换长pdf 中文出现乱码 1C

所需的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();
}
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐