Draw and detect annotation shapes in PDFs
With Nutrient Android SDK 5.3, 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, Nutrient 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 faster annotation of your documents because you don’t need to switch between different tools.
Supported transformations
We support transformations of the following drawings into their corresponding shape annotations:
-
Circles (
CircleAnnotation
) -
Rectangles (
SquareAnnotation
) -
Arrows (
LineAnnotation
with the line end set toOPEN_ARROW
) -
Lines (
LineAnnotation
without a line end)
Disabling the Magic Ink tool
The Magic Ink tool is defined as MAGIC_INK
in the AnnotationTool
enum and is included in the annotation creation toolbar by default. You can easily disable it by using #enabledAnnotationTools()
in your configuration:
val annotationTools = mutableListOf(*AnnotationTool.values())
annotationTools.remove(AnnotationTool.MAGIC_INK)
configuration.enabledAnnotationTools(annotationTools)
List<AnnotationTool> annotationTools = Arrays.asList(AnnotationTool.values()); annotationTools.remove(AnnotationTool.MAGIC_INK); configuration.enabledAnnotationTools(annotationTools);
Refer to the annotation-editing configuration guide for more details.
Stripping shape detection templates
The Nutrient library AAR contains a PSPDFShapeTemplates.json
asset file that defines shape templates used by the Magic Ink tool. This contributes to the size of your APK by approximately 900 KB. If you don’t want to use the Magic Ink tool in your app, it is recommended that you strip this asset file while building your app to decrease your app’s size.
To strip the shape templates when building, extend the android
closure in your build.gradle
file with the following:
android {
aaptOptions {
ignoreAssetsPattern "!PSPDFShapeTemplates.json"
}
}