我对这个问题很迷茫。我已经在 SO 上阅读了几乎所有关于它的帖子,如果有人能在正确的方向上插入我,我将不胜感激。
我有一个 PDF,我想提取它的文本,我只对单词和空格感兴趣。我已经设置了一个 CGPDFScanner 及其回调方法。我读到的是,就提取文本而言,我只需要考虑 4 个运算符 TJ、Tj、qout(') 和 doubleqout(")。
我想我还需要跟踪文本空间,以便能够确定字母是应该放在一起形成一个词还是应该用空格分隔。但我不知道我将如何做到这一点。
在 PDF 中,所有文本都是格式
[(X)-24.2524(X)-24.2524(X)-24.2524(Y)-24.2524(Y)-24.2524]TJ
但我无法弄清楚(使用 PDF 规范)这些数字的含义。 SO 上有人说你不应该害怕 PDF 规范,但坦率地说,我觉得它们不太容易阅读/理解。
我研究了 PDFKitten 代码,这很有帮助。
如有任何帮助,我们将不胜感激。
最佳答案
我不能给你建议如何从 PDF 中提取单词,但是
[(X)-24.2524(X)-24.2524(X)-24.2524(Y)-24.2524(Y)-24.2524]TJ
例如在 PDF 1.7 Specification 中进行了解释,“9.4.3 文本显示运算符”部分。 TJ
运算符的描述是:
Show one or more text strings, allowing individual glyph positioning. Each element of array shall be either a string or a number. If the element is a string, this operator shall show the string. If it is a number, the operator shall adjust the text position by that amount; that is, it shall translate the text matrix, Tm. The number shall be expressed in thousandths of a unit of text space.
所以数字是对字母之间距离的调整。
关于iOS PDF 到纯文本解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12465034/