In my application, I have a PDF form based on user input. I force the value in the PDF form. I was using the ILPDFKit
pod for doing this in my application (swift 3, but since PDFKit is around in iOS 11, I would to know if this is possible using PDFKit). The code I was using with ILPDFKit
was:
// set the pdf form as ILPDFDocument
let document = ILPDFDocument(resource:"ExamplePDFfrom")
// Manually set a form value for field name (created in adobe acrobat)
document.forms.setValue("David", forFormWithName: "FirstName")
Updated Answer
@objc func pdfPageChanged() {
for index in 0..<doc!.pageCount{
if let page = doc?.page(at: index){
let annotations = page.annotations
for annotation in annotations{
print("Annotation Name :: \(annotation.fieldName ?? "")")
if annotation.fieldName == "firstName"{
annotation.setValue("David", forAnnotationKey: .widgetValue)
page.removeAnnotation(annotation)
page.addAnnotation(annotation)
}else if annotation.fieldName == "checkBox"{
annotation.buttonWidgetState = .onState
page.removeAnnotation(annotation)
page.addAnnotation(annotation)
}
}
}
}
}
doc is Object of PDFDocument
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With