Magic Ink Tool: Draw and Detect Annotation Shapes

With PSPDFKit 8 for iOS, we introduced a new annotation tool: Magic Ink. This tool allows you to draw on a PDF using the ink tool. Once you finish drawing, PSPDFKit will attempt to detect the shape you have drawn. If a shape is detected with high enough confidence, the drawn ink annotation will be replaced with a shape annotation. If not, the drawing is left untouched. This allows for a faster method of annotating your documents without needing to switch between different tools.

Adding the Magic Ink Tool

The Magic Ink tool is defined as a variant of the ink tool. This tool is now included in the default presets for the annotation toolbar. If you customize the annotation toolbar and would like to add the Magic Ink tool, you can use Annotation.Variant.inkMagic in the toolbar configuration as shown in our annotation toolbar customization guide:

let configuration = AnnotationToolConfiguration(annotationGroups: [
    AnnotationToolConfiguration.ToolGroup(items: [
        AnnotationToolConfiguration.ToolItem(type: .ink, variant: .inkMagic, configurationBlock: AnnotationToolConfiguration.ToolItem.inkConfigurationBlock())
PSPDFAnnotationToolbarConfiguration *configuration = [[PSPDFAnnotationToolbarConfiguration alloc] initWithAnnotationGroups:@[
    [PSPDFAnnotationGroup groupWithItems:@[
        [PSPDFAnnotationGroupItem itemWithType:PSPDFAnnotationStringInk variant:PSPDFAnnotationStringInkMagic configurationBlock:[PSPDFAnnotationGroupItem inkConfigurationBlock]]]

The AnnotationToolConfiguration.ToolItem.inkConfigurationBlock() automatically selects the correct image for the Magic Ink variant.

Supported Transformations

We support transformations of the following drawings into their corresponding shape annotations:

Controlling Replacement Threshold

If you’d like to change the threshold at which PSPDFKit replaces the ink annotation with a shape annotation, this can be controlled using PDFConfiguration’s magicInkReplacementThreshold property.

This property should always be set to a value between 0 (always replace) and 100 (replace only for perfect matches).