Search code examples
iosswiftannotationspopuppdfkit

How to display an existing pdf annotation using ios pdfkit


I have a pdf with popup text annotations that I want to display by tapping on the annotation icon or the area where an annotation is

Having watched the 2017 wwdc pdfkit presentation it seems this should be possible. I can add new annotations to the document and remove them, and can read properties (text, colour, rect) from the existing annotation to create a new annotation

I've tried changing many properties in the annotation object e.g. isOpen, shouldDisplay, buttonWidgetState followed by pdfView.annotationsChanged(on: currPage) but nothing happens.

It seems bizarre that I can access the PDFAnnotation object to get its properties but there isn't a simple method or flag to display it.. I must be missing something! if anyone can help that would be much appreciated :)


Solution

  • It doesn't seem possible to toggle whether an existing popup annotation is displayed through pdfkit. I tested a few documents with popup annotations in the iOS Books app etc and they weren't displayed there either.

    My solution was to create a new popup annotation when tapped on, then remove it when tapped anywhere else, just one popup at a time. This way I got the text, colour and approximate location of the original popup annotation.