Magic Ink tool: Draw and detect annotation shapes
The Magic Ink tool allows users to draw on a PDF like with the regular ink tool, but after drawing finishes, Nutrient will attempt to detect the shape that was 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:
-
Circle (
CircleAnnotation
) -
Rectangle (
SquareAnnotation
) -
Arrow (
LineAnnotation
with thelineEnd
set to.openArrow
) -
Line (
LineAnnotation
without alineEnd
)
Controlling replacement threshold
If you’d like to change the threshold at which Nutrient 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).