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);
}
相关阅读:
有没有不需要配置模板的短信API
怎么样去掉移动端input的灰色背景
cordova-plugin-wechat的一些疑问
Flask 报警 NoneType object has no attribute 'delete_cookie'
Vue2.2 props验证总是出错,我开始怀疑人生
h5的canvas做游戏,提高性能最好用几层canvas
怎么编写一个collatz序列,最后获得返回值1.
怎样才能点击按钮是获取到该条新闻的数据id值,并让新闻里的字段以内容方式在单个页面显示出来
在npm发布模块包之后运行runkit的测试,但是提示Use global instead,这个应该怎么解决
js和angular同java和andorid之间的关系是一样的吗?
Oracle 对数字按位取反,SQL语句应该怎么写?
electron-boilerplate-vue运行ERR
Mac chrome search视图快捷键是?
为什么CopyFun构造函数通过new 可以继承来自Fun的属性?
使用npm在本地安装包时总是装在全局中
webview和native的选择
Angular2教程中,这里返回值为什么是heroes?
requireJS 是否能将外部html模板合并
实现一个mergeArray函数
C++中数组strlen