ios – PDFKit交换注释内容

可以在PDFKit中更改FreeText注释的文本(即内容)而不删除注释/构建新注释吗?

在PDFView中查看时,以下代码段不会更改注释的内容

let url = Bundle.main.url(forResource: "Test",withExtension: "pdf")!
let document = PDFDocument(url: url)!

for index in 0..<document.pageCount {
    let page: pdfpage = document.page(at: index)!
    let annotations = page.annotations
    for annotation in annotations {
        annotation.contents = "[REPLACED]"
    }
}
mainPDFView.document = document

这有效 – 但需要替换注释(因此必须复制注释的所有其他细节):

let url = Bundle.main.url(forResource: "Test",withExtension: "pdf")!
let document = PDFDocument(url: url)!

for index in 0..<document.pageCount {
    let page: pdfpage = document.page(at: index)!
    let annotations = page.annotations
    for annotation in annotations {
        print(annotation)
        page.removeAnnotation(annotation)
        let replacement = PDFAnnotation(bounds: annotation.bounds,forType: .freeText,withProperties: nil)

        replacement.contents = "[REPLACED]"
        page.addAnnotation(replacement)
    }
}

mainPDFView.document = document

注意:添加/删除相同的注释也没有用.

解决方法

您是否尝试在更新注释文本后调用pdfView.annotationsChanged(on:pdfpage)?

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...