kellypipe 2017-11-06 07:32 采纳率: 0%
浏览 3243
已结题

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

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程