PDFAnnotation with PDFAnnotationSubtype equal to .widget is not refreshing its appearance after adding it to PDFPage
Asked Answered
R

1

11

After adding annotation to PDFPage (and rendering it on a screen), there is no way to update its appearance on PDFPage/PDFView.

To reproduce the problem:

  1. Create PDFAnnotation and add it to the PDFPage:

    let bounds = CGRect(x: 20.0, y: 20.0, width: 200.0, height: 200.0)
    let annotation = PDFAnnotation(bounds: b, forType: .widget, withProperties: nil)
    annotation.widgetFieldType = .text
    annotation.backgroundColor = .gray
    annotation.font = .systemFont(ofSize: 18)
    annotation.widgetStringValue = "Test!"
    
    page.addAnnotation(annotation)
    
  2. After it is presented on a PDFPage, try to edit its bounds/color/background color/string value etc.:

    annotation?.setValue("Help! SOS! Mayday!", forAnnotationKey: .widgetValue)
    annotation?.color = .green
    annotation?.bounds = CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)
    

Nothing happens.

I am aware of a trick:

    page.removeAnnotation(annotation)
    page.addAnnotation(annotation)

but it is rather a workaround, not real solution.

Rightwards answered 18/10, 2017 at 16:53 Comment(0)
S
0

Can't you just use PDFAnnotation of type 'FreeText'. The size of this annotation type is updated when it's bounds are changed. I'm aware of the fact that this type is not editable by the user, but maybe you don't need this.

Slowwitted answered 20/4, 2018 at 7:42 Comment(1)
Thank you for the response. Answering your question: I can't use freeText and editing text is exactly what I need there.Lanti

© 2022 - 2024 — McMap. All rights reserved.