objective-c - PDF:字符代码 -> 字形名称 -> NSString

标签 objective-c pdf character

在跟进我之前的问题时,尝试使用 CGPDF* 函数从 PDF 文件中提取文本,具有:

CGPDFStringRef pdfString

我发现它可以转换成这样的字符代码数组:

const unsigned char *characterCodes = CGPDFStringGetBytePtr(pdfString);

现在,我要提取的文本是用 14 种 1 类基本字体之一编写的,它没有在 PDF 本身中编码。因此,我已经为该字体解析了相关的 AFM 文件,为我提供了从字符代码到字形名称的映射,它的尺寸如下所示:

C 61 ; WX 600 ; N equal ; B 80 138 520 376 ;
C 63 ; WX 600 ; N question ; B 129 -15 492 572 ;
C 64 ; WX 600 ; N at ; B 77 -15 533 622 ;
C 65 ; WX 600 ; N A ; B 3 0 597 562 ;
C 66 ; WX 600 ; N B ; B 43 0 559 562 ;

我的问题是,知道字符代码,比如:"61" 我如何从它的字形名称:"equal"NSString @ “=”。 特别是当该字符代码被 PDF 的字体编码选项重新映射到其他字形名称时,例如:“question”

以前的问题: iOS PDF parsing Type 1 Fonts metricsiOS PDF to plain text parser

最佳答案

我没有测试过这个,但在我看来你需要使用 Adobe Glyph Naming convention为此:

The purpose of the Adobe Glyph Naming convention is to support the computation of a Unicode character string from a sequence of glyphs. This is achieved by specifying a mapping from glyph names to character strings.

glyphlist.txt该页面上的链接似乎与您的问题相关。
示例片段:

...
epsilon;03B5
epsilontonos;03AD
equal;003D
equalmonospace;FF1D
equalsmall;FE66
equalsuperior;207C
...

那么您需要做的就是putting those unicode values in your NSString instance .

编辑:
确认上面提供的信息,我在PDF Reference Document from Adobe上找到了如下解释,第 5.9 节 - 提取文本内容:

If the font is a simple font that uses one of the predefined encodings MacRomanEncoding, MacExpertEncoding, or WinAnsiEncoding, or that has an encoding whose Differences array includes only character names taken from the Adobe standard Latin character set and the set of named characters in the Symbol font (see Appendix D):

  1. Map the character code to a character name according to Table D.1 on page 996 and the font’s Differences array.
  2. Look up the character name in the Adobe Glyph List (see the Bibliography) to obtain the corresponding Unicode value.

关于objective-c - PDF:字符代码 -> 字形名称 -> NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795525/

相关文章:

python - 行继续字符 python 后的语法错误意外字符

c - 如果我尝试使用 %c 和 %s 打印大整数会怎样?

bash - 如何在 Bash 中替换文件每行中除最后 n 个实例之外的所有字符实例

objective-c - 核心数据 KVO 计数

objective-c - 为什么在 Objective-C 中的字符串之前使用 '@'?

objective-c - 如何以编程方式阻止 Mac 进入休眠状态?

c# - 如何从 C# 关闭 Pdf 文件

ios - 具有旋转支持的 CGPDF drawPDFPage

objective-c - 使用 Objective-C block

php - 使用 PHP 和 Linux 从 PDF 文件中提取绘制的路径