Draw and Detect Annotation Shapes in PDFs
With PSPDFKit 5.3 for Android, 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 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);
Please refer to the Annotation-Editing Configuration guide article for more details.
Stripping Shape Detection Templates
The PSPDFKit 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"
}
}