Creating a selection rectangle for an MBS PDF annotation

I’m in the process of converting a PDF editor from MacOSLib to MBS, and some seemingly simple actions don’t translate easily. For example, how does on display a selection rectangle around an annotation when the user clicks on it, and remove it when he clicks away? I’ve spent a lot of time trying to come up with a solution, but no luck.

  1. The solution that works with MacOSLib is to place a PDFAnnotationSquare over the annotation and display just the square’s border. When the user clicks on the square the underlying annotation is selected (text, highlight, etc.). When I do the same thing with MBS the PDFAnnotationSquareMBS always gets the mouse click, it’s never received by the actual underlying annotation. Why the PDFAnnotationSquare behaves differently in MacOSLib and MBS I don’t know. I can change the z order by removing the annotation, adding the square annotation, and adding back the original, but that’s ugly and has it’s own problems. I don’t see a way to either add the square annotation below the annotation clicked on or to let the click “pass through” the PDFAnnotationSquareMBS to the underlying one.

  2. Using the border property of the annotation. This would seem to be possible from the Apple docs, but unlike PDFAnnotationSquareMBS, PDFAnnotationTextMBS and others have a border = nil. I would seem possible to create a PDFBorderMBS and add it to the annotation, but the PDFBorderMBS constructor is private.

  3. It seems you can’t simply draw a selection rectangle around the annotation in any of the DrawPage events because they don’t occur in the main thread and the plugin is ignored.

I can add a constructor for PDFBorderMBS class, to create a new object.

Thank you, if a PDFBorder can be used with any of the annotations, I think that would indeed solve the problem.

Thanks for adding PDFBorder to all annotations. However, setting it only seems to work for PDFAnnotationSquareMBS, it doesn’t work for highlights, for example. According to the Apple docs there doesn’t seem to be any limitation on which annotations should be able to display a border. But maybe it’s some cryptic issue?

I’ll sync the PDFKit plugin classes to the current macOS SDK.
This will add about 200 new items.