PDFKit注释保存文本注释

问题描述 投票:0回答:1

我有一个100页的PDF文档,我的应用程序打开了。在我的文档中,我添加了各种文本字段以允许用户添加注释。我已经尝试了各种方法来保存文本框中的文本,以允许用户返回编辑/标记文档,但我没有运气。如何将PDFAnotoation TextBox中的文本保存为带注释的字符串,以允许用户在编辑时从中断的位置进行拾取?

这是我原来的:

var textFieldMultiline21 = PDFAnnotation()    
let textFieldMultilineBounds21 = CGRect(x: 27, y: 58+2, width: 339, height: 508)
textFieldMultiline21 = PDFAnnotation(bounds: textFieldMultilineBounds21, forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.widget.rawValue), withProperties: nil)
textFieldMultiline21.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.text.rawValue)
textFieldMultiline21.backgroundColor = UIColor.clear
textFieldMultiline21.font = UIFont.systemFont(ofSize: 18)
textFieldMultiline21.isMultiline = true
page.addAnnotation(textFieldMultiline21)

这里我说尝试在文本框中保存文本:

document.page(at: 21)?.annotations[0].contents = "Sample text"
textFieldMultiline21.caption = "sampletext"
swift pdf pdfkit
1个回答
0
投票

一些简单的答案隐藏在明显的视线中

阅读文字

pdfAnnotationTextField.value(forAnnotationKey: .widgetValue)

返回带有属性的字符串值

设置文字

pdfAnnotationTextField.setValue("Enter Text", forAnnotationKey: .widgetValue)
© www.soinside.com 2019 - 2024. All rights reserved.