2

I'm working with annotations in pdf file. The problem is that text filled in annotation's text field is only visible while editing. As soon as I stop editing this text field, text disappears. I'm filling annotations this way:

for index in 0..<document.pageCount {
    if let page = document.page(at: index) {
        let annotations = page.annotations
                for annotation in annotations {
                    if annotation.fieldName == key {
                        annotation.setValue(value, forAnnotationKey: .widgetValue)
                        page.removeAnnotation(annotation)
                        page.addAnnotation(annotation)
                    }
                }
            }
        }

It works only in some documents. I even tried creating new PDF file and then adding forms to it, but the same thing again.

Alexandr Chekel
  • 382
  • 2
  • 15
  • 1
    Maybe your `key` variable is the problem. What is the key, you didnt show it in your code. If the key is wrong, the `if`` wouldnt be executed – Jonathan Dec 13 '18 at 06:21

1 Answers1

-1

Set the annotation widgetStringValue property:

annotation.widgetStringValue = value.description
Alain Bianchini
  • 3,883
  • 1
  • 7
  • 27