现象
加载PDF显示乱码,提示非嵌入字体
bash
non-embedded font using identity encoding
调式
在pdf-font.c中加载字体
调试源码发现pdf文档的字体名字居然是GBK,估计又是哪个windows下写的pdf生成工具生成pdf
字体方法:
c
static pdf_font_desc *
load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_unicode)
具体加载
c
pdf_to_name(ctx, pdf_dict_get(ctx, dict, PDF_NAME(BaseFont)));
解决
转码发现是宋体,简单判断转换下
c
unsigned char utf8SimSun[]={0xe5,0xae,0x8b,0xe4,0xbd,0x93};
unsigned char gbkSimSun[]={0xcb,0xce,0xcc,0xe5};
cpp
if(0 == memcmp(basefont,utf8SimSun,sizeof(utf8SimSun))){
fz_warn(ctx, "basefont:宋体UTF8");
basefont = "SimSun";
}
if(0 == memcmp(basefont,gbkSimSun,sizeof(gbkSimSun))){
fz_warn(ctx, "basefont:宋体GBK");
basefont = "SimSun";
}
PDF字体查看
可以借助福昕软件查看