java导出pdf字体宋体不加粗_docx4j word转pdf 中文宋体(中文正文)类型转换乱码...
使用docx4j生成pdf時,宋體(中文正文)類型無法轉換成功。如何配置支持宋體(中文正文)類型字體?
轉換結果為:
代碼:
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);
}
總結
以上是生活随笔為你收集整理的java导出pdf字体宋体不加粗_docx4j word转pdf 中文宋体(中文正文)类型转换乱码...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java插入数据库字段过长_数据库插入数
- 下一篇: java监理的职责_承担监理业务和监理责