通过XPDF读取PDF内容并转化为txt格式的过程中,可能会出现如下提示:
Syntax Error: Unknown character collection 'Adobe-GB1'
Syntax Error: Couldn't find 'UniGB-UTF16-H' CMap file for 'Adobe-GB1' collection
Syntax Error: Unknown CMap 'UniGB-UTF16-H' for character collection 'Adobe-GB1'
Syntax Error: Failed to parse font object for 'AdobeSongStd-Light'
该如何处理呢,下面慢慢道来,先说软件下载地址:
http://www.xpdfreader.com/download.html
http://www.xpdfreader.com/pdftotext-man.html
下载这三个压缩包,运行XpdfReader-win64-4.03.exe,将其安装到D:\Program Files\xpdf\ 目录下,将中文语言包xpdf-chinese-simplified.tar.gz解压缩到该目录下,如下图所示:
这个时候,如果我们开始运行转换命令,仍然会报错,
这是因为我们仍缺少最后一步的配置操作:将D:\Program Files\xpdf\xpdf-chinese-simplified\目录下面的add-to-xpdfrc文件复制到D:\Program Files\xpdf\bin64\目录下,将其改名为xpdfrc,打开该文件修改内容为如下:
#----- begin Chinese Simplified support package (2011-sep-02)
textEncoding UTF-8
textPageBreaks no
cidToUnicode Adobe-GB1 "D:\Program Files\xpdf\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode"
unicodeMap ISO-2022-CN "D:\Program Files\xpdf\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap"
unicodeMap EUC-CN "D:\Program Files\xpdf\xpdf-chinese-simplified\EUC-CN.unicodeMap"
unicodeMap GBK "D:\Program Files\xpdf\xpdf-chinese-simplified\GBK.unicodeMap"
cMapDir Adobe-GB1 "D:\Program Files\xpdf\xpdf-chinese-simplified\CMap"
toUnicodeDir "D:\Program Files\xpdf\xpdf-chinese-simplified\CMap"
#fontFileCC Adobe-GB1 /usr/..../NotoSansCJKsc-Regular.otf
#----- end Chinese Simplified support package
或者,为了移植性更好,可以配置如下:
#----- begin Chinese Simplified support package (2011-sep-02)
textEncoding UTF-8
textPageBreaks no
cidToUnicode Adobe-GB1 ..\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN ..\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap
unicodeMap EUC-CN ..\xpdf-chinese-simplified\EUC-CN.unicodeMap
unicodeMap GBK ..\xpdf-chinese-simplified\GBK.unicodeMap
cMapDir Adobe-GB1 ..\xpdf-chinese-simplified\CMap
toUnicodeDir ..\xpdf-chinese-simplified\CMap
#fontFileCC Adobe-GB1 /usr/..../NotoSansCJKsc-Regular.otf
#----- end Chinese Simplified support package
尤其要注意,因为文件路径中含有空格,所以要加引号。该配置文件的行前的关键字严格区分大小写,务必保持原样。
总结如下:
xpdfrc文件放到pdftotext.exe所在同一目录,也就是bin64或bin32目录下,这点官方文档说明的不是很清楚。
xpdfrc里面的配置内容中的路径最好不要空格,有空格的话要加引号
或者直接从以下位置下载我已经配置好的文件:https://download.csdn.net/download/xcntime/16277001