博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

解决GhostScript无法转换中文PDF的问题

Posted on 2013-12-18 12:39  ^e^boy  阅读(3072)  评论(0)    收藏  举报

使用 GhostScript 转换 PDF 为图片时,报如下错误。

 

GPL Ghostscript 8.61 (2007-11-21)
Copyright (C) 2007 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 108.
Page 1
Substituting CID font resource/Adobe-GB1 for /STXinwei.
Error: /undefinedresource in findresource
Operand stack:
--nostringval-- --dict:8/17(L)-- TT2 1 --dict:5/5(L)-- --dict:5/5(L
)-- STXinwei --dict:11/12(ro)(G)-- --nostringval-- --dict:7/7(L)-- --d
ict:7/7(L)-- Adobe-GB1 CIDFont Adobe-GB1

 

然后就停止转换了,后来百度下,应该是不支持中文字体的缘故。

 

解决方案:

先查看 GhostScript 安装目录下 C:\Program Files (x86)\gs\gs8.61\lib 有没有 cidfmap 这个文件,如果没有执行下面的命令来创建:

 

bin\gswin32c -q -dBATCH -sFONTDIR=c:/windows/fonts -sCIDFMAP=lib/cidfmap lib/mkcidfm.ps

 

打开文件,可以看到以下内容:

%!
% cidfmap generated automatically by mkcidfm.ps from fonts found in
% c:/windows/fonts

% Substitutions
/Gungsuh << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/batang.ttc) /SubfontID 2 >> ;
/GungsuhChe << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/batang.ttc) /SubfontID 3 >> ;
/MingLiU << /CSI [(CNS1) 2] /FileType /TrueType /Path (c:/windows/fonts/mingliu.ttc) /SubfontID 0 >> ;
/SimSun << /CSI [(GB1) 2] /FileType /TrueType /Path (c:/windows/fonts/simsun.ttc) /SubfontID 0 >> ;
/Gulim << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/gulim.ttc) /SubfontID 0 >> ;
/MS-UI-Gothic << /CSI [(Japan1) 3] /FileType /TrueType /Path (c:/windows/fonts/msgothic.ttc) /SubfontID 2 >> ;
/BatangChe << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/batang.ttc) /SubfontID 1 >> ;
/MS-PGothic << /CSI [(Japan1) 3] /FileType /TrueType /Path (c:/windows/fonts/msgothic.ttc) /SubfontID 1 >> ;
/DotumChe << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/gulim.ttc) /SubfontID 3 >> ;
/NSimSun << /CSI [(GB1) 2] /FileType /TrueType /Path (c:/windows/fonts/simsun.ttc) /SubfontID 1 >> ;
/MS-Gothic << /CSI [(Japan1) 3] /FileType /TrueType /Path (c:/windows/fonts/msgothic.ttc) /SubfontID 0 >> ;
/SimHei << /CSI [(GB1) 2] /FileType /TrueType /Path (c:/windows/fonts/simhei.ttf) /SubfontID 0 >> ;
/Dotum << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/gulim.ttc) /SubfontID 2 >> ;
/MS-Mincho << /CSI [(Japan1) 3] /FileType /TrueType /Path (c:/windows/fonts/msmincho.ttc) /SubfontID 0 >> ;
/MS-PMincho << /CSI [(Japan1) 3] /FileType /TrueType /Path (c:/windows/fonts/msmincho.ttc) /SubfontID 1 >> ;
/Batang << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/batang.ttc) /SubfontID 0 >> ;
/GulimChe << /CSI [(Korea1) 3] /FileType /TrueType /Path (c:/windows/fonts/gulim.ttc) /SubfontID 1 >> ;
/PMingLiU << /CSI [(CNS1) 2] /FileType /TrueType /Path (c:/windows/fonts/mingliu.ttc) /SubfontID 1 >> ;

% Aliases
/HYRGoThic-Medium /Gulim ;
/HYSMyeongJo-Medium /Batang ;
/STHeiti-Regular /SimHei ;
/STFangsong-Light /SimSun ;
/Ryumin-Light /MS-Mincho ;
/STKaiti-Regular /SimHei ;
/MKai-Medium /MingLiU ;
/MHei-Medium /MingLiU ;
/HYGoThic-Medium /Dotum ;
/HeiseiKakuGo-W5 /MS-Gothic ;
/HeiseiMin-W3 /MS-Mincho ;
/MSung-Medium /MingLiU ;
/Ryumin-Medium /MS-Mincho ;
/MSung-Light /MingLiU ;
/GothicBBB-Medium /MS-Gothic ;
/STSong-Light /SimSun ;

 

例如上面报错 “Substituting CID font resource/Adobe-GB1 for /STXinwei.” 在文件的 % Substitutions 区增加如下内容:

/STXinwei << /CSI [(GB1)1] /FileType /TrueType /Path (c:/windows/fonts/STXINWEI.TTF) /SubfontID 0 >> ;

指示 GhostScript 去查找字体文件。

 

也可以在 % Aliases 区增加

/Adobe-GB1 /SimSun ;

 

但是这样的话,所有找不到的字体,都会使用 SimSun 字体来显示。