GhostScriptでPDF変換するとフォントが適用されなくなることがある

受け売りですがすいません

一緒に働いているhanzouさんから教えてもらいましたが、
きっと困っている人が沢山いそうなので私も書こう…。<< GhostScriptでMSゴシックを出力する方法 >>
http://www.hanzou.jp/tech/index.php?GhostScript%E3%81%A7%EF%BC%AD%EF%BC%B3%E3%82%B4%E3%82%B7%E3%83%83%E3%82%AF%E3%82%92%E5%87%BA%E5%8A%9B%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95

GhostScriptのインストール

http://www.ghostscript.com/
今回は「gs916w32.exe」を利用しています。

変換Script

<<インストールディレクトリ>>\bin\gswin32c.exe -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -sOutputFile="出力画像ファイル名%02d.png PDFファイル名.pdf

文字化け発生

以下のようにPDFではきちんとMSゴシックになっていますが、
GhostSciriptを経由するとフォントが適用されず、
他のフォントになってしまっています。

フォントの指定がおかしいのかと考えますよね。
なので、libフォルダにあるcidfmapというファイルを開きます。
以下のようにMSゴシックあるはずなんだけどなぁ…。ってなります。

…
/Gungsuh << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /SubfontID 2 /FileType /TrueType >> ;
/ArialUnicodeMS-GB << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/arialuni.ttf) /SubfontID 0 /FileType /TrueType >> ;
/MS-Mincho << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msmincho.ttc) /SubfontID 0 /FileType /TrueType >> ;
/Meiryo-BoldItalic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/meiryob.ttc) /SubfontID 1 /FileType /TrueType >> ;
/MalgunGothicRegular << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/malgun.ttf) /SubfontID 0 /FileType /TrueType >> ;
/MS-PMincho << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msmincho.ttc) /SubfontID 1 /FileType /TrueType >> ;
/Batang << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /SubfontID 0 /FileType /TrueType >> ;
/Gulim << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /SubfontID 0 /FileType /TrueType >> ;
/MS-PGothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /SubfontID 1 /FileType /TrueType >> ;
/MingLiU << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/mingliu.ttc) /SubfontID 0 /FileType /TrueType >> ;
/DotumChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /SubfontID 3 /FileType /TrueType >> ;
/MS-Gothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /SubfontID 0 /FileType /TrueType >> ;
/SimHei << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simhei.ttf) /SubfontID 0 /FileType /TrueType >> ;
/BatangChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /SubfontID 1 /FileType /TrueType >> ;
…

解決法

MSゴシックという文字(全角なのがミソです)を
SJIS(16進)変換してあげてcidfmapに追記してみます。
ちなみに変換は以下のサイトを使うと便利です。
http://www.ahref.org/app/mozicode/

…
/Gungsuh << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /SubfontID 2 /FileType /TrueType >> ;
/ArialUnicodeMS-GB << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/arialuni.ttf) /SubfontID 0 /FileType /TrueType >> ;
/MS-Mincho << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msmincho.ttc) /SubfontID 0 /FileType /TrueType >> ;
/Meiryo-BoldItalic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/meiryob.ttc) /SubfontID 1 /FileType /TrueType >> ;
/MalgunGothicRegular << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/malgun.ttf) /SubfontID 0 /FileType /TrueType >> ;
/MS-PMincho << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msmincho.ttc) /SubfontID 1 /FileType /TrueType >> ;
/Batang << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /SubfontID 0 /FileType /TrueType >> ;
/Gulim << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /SubfontID 0 /FileType /TrueType >> ;
/MS-PGothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /SubfontID 1 /FileType /TrueType >> ;
/MingLiU << /CSI [(CNS1) 2] /Path (C:/Windows/Fonts/mingliu.ttc) /SubfontID 0 /FileType /TrueType >> ;
/DotumChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/gulim.ttc) /SubfontID 3 /FileType /TrueType >> ;
/MS-Gothic << /CSI [(Japan1) 3] /Path (C:/Windows/Fonts/msgothic.ttc) /SubfontID 0 /FileType /TrueType >> ;
/SimHei << /CSI [(GB1) 2] /Path (C:/Windows/Fonts/simhei.ttf) /SubfontID 0 /FileType /TrueType >> ;
/BatangChe << /CSI [(Korea1) 3] /Path (C:/Windows/Fonts/batang.ttc) /SubfontID 1 /FileType /TrueType >> ;
<826C8272835383568362834E>cvn << /Path (C:/WINDOWS/Fonts/msgothic.ttc) /FileType /TrueType /SubfontID 0 /CSI [(Japan1) 3] >> ;

再度実行


うまくいきました。