使用pdfBox实现pdf转图片出现中文方块乱码简单修改源码解决

更新时间:2023-06-14 06:26:58 阅读: 评论:0

使⽤pdfBox实现pdf转图⽚出现中⽂⽅块乱码简单修改源码解决
玩魔方的口诀公式
参考⽂章
pdfbox版本是2.0
⽇志中打印出类似这样的⽇志(例:Using fallback XXX for CID-keyed font STSong-Light),就说明系统没有安装STSong-Light字体,pdfbox使⽤XXX字体来替代了。如果出现⽅块,就说明没有这种字体,并且替代字体也没有,⽇志也有相应的其他提⽰。
正常操作就是安装缺失的 STSong-Light 字体,但是在⽹上搜到的都是 STSong 字体安装后没效果 我的是windows10
参考上⾯⽂章(请⼀定看⼀下),修改 FontMapperImpl 在substitutes中增加映射字体STSong-Light->STFangsong
从Apache 下载pdfbox 修改 \pdfbox\src\main\java\org\apache\pdfbox\pdmodel\font\FontMapperImpl.java
final class FontMapperImpl implements FontMapper
{
private static final FontCache fontCache =new FontCache();// todo: static cache isn't ideal private FontProvider fontProvider;
private Map<String, FontInfo> fontInfoByName;
private final TrueTypeFont lastResortFont;
/** Map of PostScript name substitutes, in priority order. */
private final Map<String, List<String>> substitutes =new HashMap<String, List<String>>();
FontMapperImpl()
{
// substitutes for standard 14 fonts
substitutes.put("Courier",
最美南粤少年
Arrays.asList("CourierNew","CourierNewPSMT","LiberationMono","NimbusMonL-Regu"));        substitutes.put("Courier-Bold",
Arrays.asList("CourierNewPS-BoldMT","CourierNew-Bold","LiberationMono-Bold", "NimbusMonL-Bold"));
substitutes.put("Courier-Oblique",
Arrays.asList("CourierNewPS-ItalicMT","CourierNew-Italic",
"LiberationMono-Italic","NimbusMonL-ReguObli"));
substitutes.put("Courier-BoldOblique",
Arrays.asList("CourierNewPS-BoldItalicMT","CourierNew-BoldItalic",
"LiberationMono-BoldItalic","NimbusMonL-BoldObli"));
substitutes.put("Helvetica",
Arrays.asList("ArialMT","Arial","LiberationSans","NimbusSanL-Regu"));
substitutes.put("Helvetica-Bold",
Arrays.asList("Arial-BoldMT","Arial-Bold","LiberationSans-Bold",
"NimbusSanL-Bold"));
substitutes.put("Helvetica-Oblique",
Arrays.asList("Arial-ItalicMT","Arial-Italic","Helvetica-Italic",
"LiberationSans-Italic","NimbusSanL-ReguItal"));
substitutes.put("Helvetica-BoldOblique",
冬日阳光
Arrays.asList("Arial-BoldItalicMT","Helvetica-BoldItalic",
"LiberationSans-BoldItalic","NimbusSanL-BoldItal"));
网络广告推广substitutes.put("Times-Roman",
Arrays.asList("TimesNewRomanPSMT","TimesNewRoman","TimesNewRomanPS", "LiberationSerif","NimbusRomNo9L-Regu"));
substitutes.put("Times-Bold",
Arrays.asList("TimesNewRomanPS-BoldMT","TimesNewRomanPS-Bold",
"TimesNewRoman-Bold","LiberationSerif-Bold",
"NimbusRomNo9L-Medi"));
substitutes.put("Times-Italic",
Arrays.asList("TimesNewRomanPS-ItalicMT","TimesNewRomanPS-Italic",
"TimesNewRoman-Italic","LiberationSerif-Italic",
"NimbusRomNo9L-ReguItal"));
substitutes.put("Times-BoldItalic",
Arrays.asList("TimesNewRomanPS-BoldItalicMT","TimesNewRomanPS-BoldItalic", "TimesNewRoman-BoldItalic","LiberationSerif-BoldItalic",
青瓜的营养价值
"NimbusRomNo9L-MediItal"));
substitutes.put("Symbol", Arrays.asList("Symbol","SymbolMT","StandardSymL"));
substitutes.put("ZapfDingbats", Arrays.asList("ZapfDingbatsITC","Dingbats","MS-Gothic"));
// FIXME believelelf STSong-Light->STFangsong, SimSun(宋体)
substitutes.put("STSong-Light", Arrays.asList("STFangsong","SIMFANG","SimSun"));
substitutes.put("STSong-Light-UniGB-UCS2-H", Arrays.asList("SimSun"));
// Acrobat also us alternative names for Standard 14 fonts, which we map to tho above
// the include names such as "Arial" and "TimesNewRoman"
...
按照官⽹说明⽤maven编译打包 我使⽤的jdk7
使⽤修改过的jar包乱码问题解决
提取码:m4eo
关于阳光的诗句
从官⽹下载源码⼀些说明:
maven编译打包的说明
按照说明 在.\pdfbox ⽂件夹下 运⾏ mvn clean install
怀孕什么不能吃但是会运⾏ test,我这⾥会报错 所以我关闭了测试 mvn clean install -DskipTests
酒店客房保洁
鄙⼈就是⼀菜鸟,如果有好的解决⽅法或思路 欢迎留⾔
希望⽂章能帮到⼤家 谢谢

本文发布于:2023-06-14 06:26:58,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/950498.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:字体   说明   安装   解决   关闭   没有
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图