Magic Ink

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 PSPDFAnnotationVariantStringInkMagic in the toolbar configuration as shown in our annotation toolbar customization guide:

Copy
1
2
3
4
5
let configuration = PSPDFAnnotationToolbarConfiguration(annotationGroups: [
        PSPDFAnnotationGroup(items: [
            PSPDFAnnotationGroupItem(type: .ink, variant: .inkMagic, configurationBlock: PSPDFAnnotationGroupItem.inkConfigurationBlock())
        ])
])
Copy
1
2
3
4
5
PSPDFAnnotationToolbarConfiguration *configuration = [[PSPDFAnnotationToolbarConfiguration alloc] initWithAnnotationGroups:@[
    [PSPDFAnnotationGroup groupWithItems:@[
        [PSPDFAnnotationGroupItem itemWithType:PSPDFAnnotationStringInk variant:PSPDFAnnotationStringInkMagic configurationBlock:[PSPDFAnnotationGroupItem inkConfigurationBlock]]]
    ]
]];

The +[PSPDFAnnotationGroupItem 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 PSPDFConfiguration’s magicInkReplacementThreshold property.

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