ios – PDFKit交换注释内容

前端之家收集整理的这篇文章主要介绍了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)?
原文链接:https://www.f2er.com/iOS/331233.html

猜你在找的iOS相关文章