【发布时间】:2019-10-03 15:19:33
【问题描述】:
我正在尝试在 macOS 应用程序中使用 PDFkit 提取所有亮点。这是我正在使用的代码:
guard let path = item.filePath else { return }
let document = PDFDocument(url: URL(fileURLWithPath: path))
guard let numberOfPage = document?.pageCount else { return }
for i in 0...numberOfPage - 1 {
let pages = document?.page(at: i)
guard let annotations = pages?.annotations else { continue }
for annotation in annotations {
if annotation.type == "Highlight" {
print(annotation.contents)
self.annotations.append(annotation)
}
}
}
问题是print(annotation.contents) 总是返回“Optional("")”。我尝试了几个pdf,结果总是一样的。问题是,如果我执行print(annotation.color),它会返回给定高光的正确颜色。
我的代码有什么我没有弄清楚的问题吗?还是这是 PDFKit 的正常行为?
【问题讨论】:
-
我对 PDFKit 了解不多,但
"Highlight"看起来很可疑。也许使用PDFAnnotationSubtype.highlight有帮助? -
我试过但没用,
annotation.type是字符串,PDFAnnotationSubtype.highlight不是。无论如何,感谢您的尝试;)