0

I use PDFKit in iOS as PDF renderer and I have problem with background color in radio button.

I iterate all PDF annotations on all pages in the document.

override func viewDidAppear(_ animated: Bool) {
  //let pdfData = ... received data from file storage ...
  if let document = PDFDocument(data: pdfData) {
    for i in 0...document.pageCount {
      if let page = document.page(at: i) {
         for annot in page.annotations {
           if annot.widgetControlType == .radioButtonControl {
              annot.backgroundColor = UIColor.red
           }
         }         
       }
     }
   }
}

When I set the background color, nothing happens. But when I try to set the background color to the type of Text annotation, the color changes.

The difference between the Radio button and the Text annotation is in its type. The Radio button has a widgetFieldType == .button and the Text has a widgetFieldType == .text.

I think this is the reason why it doesn't work.

Next I try to remove annotation, change his background color and add again. This also doesn't work.

if annot.widgetControlType == .radioButtonControl {
  page.removeAnnotation(annot)
  annot.backgroundColor = UIColor.red
  page.addAnnotation(annot)
}

But when I create a new instance of PDFAnnotaion, and I add it to the page, it works.

if annot.widgetControlType == .radioButtonControl {
  page.removeAnnotation(annot)
  let newAnnot = PDFAnnotation(bounds: annot.bounds, forType: .widget, withProperties: nil)
  newAnnot.backgroundColor = UIColor.red
  newAnnot.widgetStringValue = annot.widgetStringValue
  page.addAnnotation(newAnnot)
}

The big problem is that the value of this Radio button is not displayed, even though it contains the value itself. If in another method I get all the values from PDF annotations, there is also the right value from this radio button. The Radio button contains the value, only it is displayed.

I tried to copy all the properties PDF annotation from the annot to newAnnot, but it didn't help.

How to properly change the background color of the Radio button and display its value?

Puty
  • 100
  • 1
  • 13
  • Hi puty did you find out the answer to your question – Codicil Feb 10 '20 at 06:49
  • Hi Codicil, since PDFKit has a lot of other bugs, I finally decided on another solution. In my case the pdfs are not large (number of pages) so I render them asynchronously into images and manually render the active layer with controls above the images. – Puty Feb 11 '20 at 07:05
  • By the way what widget string value was assigned to your radio button, – Codicil Feb 15 '20 at 07:13

0 Answers0