Last Updated: February 25, 2016
·
1.187K
· adamyanalunas

Control your annotation menu items in PSPDFKit

You can control which items end up in the annotation menu of your PSPDFKit instance. If you're subclassing, here's a good place to start:

- (void)commonInitWithDocument:(PSPDFDocument *)document
{
    [super commonInitWithDocument:document];

    self.createAnnotationMenuTypes = [NSSet setWithObjects: 
                            PSPDFAnnotationStringSquare,
                            PSPDFAnnotationStringCircle,
                            PSPDFAnnotationStringPolygon,
                            PSPDFAnnotationStringPolyLine,
                            PSPDFAnnotationStringLine,
                            nil];
}

You can adjust the types at any point in the PDFViewController's life, whether it's subclassed or not. Maybe you want to change the list based on what's being highlighted. Try pdfViewController:shouldShowMenuItems:atSuggestedTargetRect:forSelectedText:inRect:onPageView:. Really, as long as the controller is loaded go nuts.

Edit: Peter Steinberger (creator of PSPDFKit) reminded me that you don't have to subclass to edit these values. Copy has been updated to reflect that.

For reference, here are the annotation types you can use:

  • PSPDFAnnotationStringLink
  • PSPDFAnnotationStringHighlight
  • PSPDFAnnotationStringUnderline
  • PSPDFAnnotationStringSquiggly
  • PSPDFAnnotationStringStrikeOut
  • PSPDFAnnotationStringNote
  • PSPDFAnnotationStringCaret
  • PSPDFAnnotationStringFreeText
  • PSPDFAnnotationStringInk
  • PSPDFAnnotationStringSquare
  • PSPDFAnnotationStringCircle
  • PSPDFAnnotationStringLine
  • PSPDFAnnotationStringSignature
  • PSPDFAnnotationStringStamp
  • PSPDFAnnotationStringImage
  • PSPDFAnnotationStringWidget
  • PSPDFAnnotationStringFile
  • PSPDFAnnotationStringSound
  • PSPDFAnnotationStringPolygon
  • PSPDFAnnotationStringPolyLine
  • PSPDFAnnotationStringRichMedia
  • PSPDFAnnotationStringScreen
  • PSPDFAnnotationStringPopup