java word转html乱码怎么办_【java】docx4j word转pdf 中文宋体(中文正文)类型转换乱码...

使用docx4j生成pdf时,宋体(中文正文)类型无法转换成功。如何配置支持宋体(中文正文)类型字体?

e2d9033663f2c7b2fa4be1c0bd8fca0c.png

转换结果为:

1da4727d29194c0e1248cc8979280c91.png

代码:

String tempPath = "G:\\TestDoc\\weituo2.docx";

WordprocessingMLPackage wordMLPackage = DocxUtils.getWordMLPackage(tempPath);

String outpath = "G:\\TestDoc\\业务委托单.pdf";

DocxUtils.toPDF(wordMLPackage,outpath);

public static void toPDF(WordprocessingMLPackage wordMLPackage,String outPath) throws Exception{

// Mapper fontMapper = new IdentityPlusMapper();

Mapper fontMapper = new IdentityPlusMapper();

wordMLPackage.setFontMapper(fontMapper);

// PhysicalFont font = PhysicalFonts.getPhysicalFonts().get("Arial Unicode MS");

// if (font!=null) {

// fontMapper.getFontMappings().put("Times New Roman", font);

// }

fontMapper.put("隶书", PhysicalFonts.get("LiSu"));

fontMapper.put("宋体",PhysicalFonts.get("SimSun"));

fontMapper.put("微软雅黑",PhysicalFonts.get("Microsoft Yahei"));

fontMapper.put("黑体",PhysicalFonts.get("SimHei"));

fontMapper.put("楷体",PhysicalFonts.get("KaiTi"));

fontMapper.put("新宋体",PhysicalFonts.get("NSimSun"));

fontMapper.put("华文行楷", PhysicalFonts.get("STXingkai"));

fontMapper.put("华文仿宋", PhysicalFonts.get("STFangsong"));

fontMapper.put("宋体扩展",PhysicalFonts.get("simsun-extB"));

fontMapper.put("仿宋",PhysicalFonts.get("FangSong"));

fontMapper.put("仿宋_GB2312",PhysicalFonts.get("FangSong_GB2312"));

fontMapper.put("幼圆",PhysicalFonts.get("YouYuan"));

fontMapper.put("华文宋体",PhysicalFonts.get("STSong"));

fontMapper.put("华文中宋",PhysicalFonts.get("STZhongsong"));

DocxUtils.toP(wordMLPackage,outPath);

}

public static void toP(WordprocessingMLPackage wordMLPackage,String outPath) throws Exception{

OutputStream os = new FileOutputStream(outPath);

FOSettings foSettings = Docx4J.createFOSettings();

foSettings.setWmlPackage(wordMLPackage);

Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);

}

回答

org.docx4j

docx4j-export-fo

3.3.0

这个版本

楼主找到解决方法了吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值