PDF Annotations#
Annotations#
Annotations includes functionality for drawing, text markup and placing objects on a PDF document.
App Kit provides the following sets:
- Document Drawing
Freehand ink drawing
Line
Rectangle
Ellipse
Polygon
Polyline
- Document Text
Highlight
Underline
Squiggle
Strikethrough
- Document Placement
Note
Textbox
Stamp
Attachment
Link
Note
You should not set annotation modes on a document until the document has loaded, therefore ensure to add any API calls for annotation methods after listening for the document loaded event.
Document Drawing Annotations#
Document text annotations depend on a “Drawing Annotation Mode” being activated. The following API allows for control over setting this mode as well as finding out what mode is currently active.
Draw Mode#
Turning on drawing is as simple as calling the setDrawModeOn()
method against your DocumentView
instance. To turn off drawing just call the setDrawModeOff()
method against your DocumentView
instance.
import com.artifex.sonui.editor.DocumentView
fun setDocumentDrawMode(documentView:DocumentView, enable:Boolean) {
if (enable) {
documentView.setDrawModeOn()
} else {
documentView.setDrawModeOff()
}
}
import com.artifex.sonui.editor.DocumentView;
public void setDocumentDrawMode(documentView:DocumentView, enable:Boolean) {
if (enable) {
documentView.setDrawModeOn();
} else {
documentView.setDrawModeOff();
}
}
To test if “Draw Mode” is active you can use isDrawModeOn
val dm:Boolean = documentView.isDrawModeOn
Boolean dm = documentView.isDrawModeOn();
When Draw Mode is enabled, the user can draw an ink annotation with the selected line thickness and color. When Draw Mode is then disabled, the annotation is saved to the document.
Drawing Mode Annotation Types#
The simplist drawing annotation is freehand ink drawing. As this was the first supported drawing annotation, in the Android App Kit SDK this is the default implementation. Therefore calling setDrawModeOn()
without any parameter will enable ink annotations.
For other drawing types use the following with the setDrawModeOn
method:
Drawing mode enumeration#
|
Description |
---|---|
|
None |
|
Freehand ink |
|
Line |
|
Rectangle |
|
Oval |
|
Polygon |
|
Polyline |
|
Arrow |
documentView.drawMode = DocView.AnnotMode.LINE
documentView.setDrawModeOn(DocView.AnnotMode.LINE);
When a “Drawing Annotation Mode” is disabled, the annotation is saved to the document.
Getting Draw Mode#
To get the current draw mode use the getDrawMode
method:
val dm:DocView.AnnotMode = documentView.drawMode
DocView.AnnotMode dm = mDocumentView.getDrawMode();
Styling Drawing Annotations#
Drawing annotations can be styled as follows:
Opacity#
To get/set the opacity use the API as follows:
val color:Int = documentView.lineColor // getter
documentView.lineColor = 0xFF00FF00 // setter
int color = documentView.getLineColor(); // getter
documentView.setLineColor(0xFF00FF00); // setter
Line Thickness#
To get/set the line thickness use the API as follows:
val thickness:Float = documentView.lineThickness // getter
documentView.lineThickness = 2.0f // setter
float thickness = documentView.getLineThickness(); // getter
documentView.setLineThickness(2.0f); // setter
Line Color#
To get/set the line color use the API as follows:
val color:Int = documentView.lineColor // getter
documentView.lineColor = 0xFF00FF00 // setter
int color = documentView.getLineColor(); // getter
documentView.setLineColor(0xFF00FF00); // setter
Line Endings#
Line endings are only supported for the DocView.AnnotMode.LINE
annotation. They can be set against the start & end of the line as follows:
documentView.setLineEndStyles(DocumentViewPdf.LINE_ENDING_BUTT, DocumentViewPdf.LINE_ENDING_CIRCLE)
documentView.setLineEndStyles(DocumentViewPdf.LINE_ENDING_BUTT, DocumentViewPdf.LINE_ENDING_CIRCLE);
Line ending enumeration#
|
Description |
---|---|
|
None |
|
Butt |
|
Slash |
|
Cirle |
|
Diamond |
|
Open arrow |
|
Right pointing open arrow |
|
Square |
|
Closed arrow |
|
Right pointing closed arrow |
Document Text Annotations#
Document text annotations depend on a “Text Annotation Mode” being activated. The following API allows for control over setting this mode as well as finding out what mode is currently active.
Find the Document Text Annotation Mode#
val isHighlightMode:Boolean = documentView.isTextHighlightModeOn
val isTextSquigglyModeOn:Boolean = documentView.isTextSquigglyModeOn
val isTextStrikeThroughModeOn:Boolean = documentView.isTextStrikeThroughModeOn
val isTextUnderlineModeOn:Boolean = documentView.isTextUnderlineModeOn
Boolean isHighlightMode = documentView.isTextHighlightModeOn();
Boolean isTextSquigglyModeOn = documentView.isTextSquigglyModeOn();
Boolean isTextStrikeThroughModeOn = documentView.isTextStrikeThroughModeOn();
Boolean isTextUnderlineModeOn = documentView.isTextUnderlineModeOn();
Toggle the text mode#
Text Highlight Mode#
documentView.toggleTextHighlightMode()
documentView.toggleTextHighlightMode();
Text Squiggly Mode#
documentView.toggleTextSquigglyMode()
documentView.toggleTextSquigglyMode();
Text Strikethrough Mode#
documentView.toggleTextStrikeThroughMode()
documentView.toggleTextStrikeThroughMode();
Text Underline Mode#
documentView.toggleTextUnderlineMode()
documentView.toggleTextUnderlineMode();
Highlighting Selected Text#
Another quick method to highlight selected text is to call the highlightSelection()
method against your DocumentView
instance.
documentView.highlightSelection()
documentView.highlightSelection();
Note
Without a text selection being present in your document view calling highlightSelection()
will have no effect.
Document Placement Annotations#
Document placement annotations depend on a “Placement Annotation Mode” being activated. The following API allows for control over setting this mode as well as finding out what mode is currently active.
Find the Document Placement Annotation Mode#
val isNoteModeOn:Boolean = documentView.isNoteModeOn
val isTextModeOn:Boolean = documentView.isTextModeOn
val isStampModeOn:Boolean = documentView.isStampModeOn
val isAttachmentModeOn:Boolean = documentView.isAttachmentModeOn
val isLinkModeOn:Boolean = documentView.isLinkModeOn
Boolean isNoteModeOn = documentView.isNoteModeOn();
Boolean isTextModeOn = documentView.isTextModeOn();
Boolean isStampModeOn = documentView.isStampModeOn();
Boolean isAttachmentModeOn = documentView.isAttachmentModeOn();
Boolean isLinkModeOn = documentView.isLinkModeOn();
Setting Note Mode#
Setting Note Mode On#
documentView.setNoteModeOn()
documentView.setNoteModeOn();
Setting Note Mode Off#
documentView.setNoteModeOff()
documentView.setNoteModeOff();
Setting Text Mode#
Setting Text Mode On#
documentView.setTextModeOn()
documentView.setTextModeOn();
Setting Text Mode Off#
documentView.setTextModeOff()
documentView.setTextModeOff();
Setting Stamp Mode#
Setting Stamp Mode On#
documentView.setStampModeOn()
documentView.setStampModeOn();
Setting Stamp Mode Off#
documentView.setStampModeOff()
documentView.setStampModeOff();
Setting Attachment Mode#
Setting Attachment Mode On#
documentView.setAttachmentModeOn()
documentView.setAttachmentModeOn();
Setting Attachment Mode Off#
documentView.setAttachmentModeOff()
documentView.setAttachmentModeOff();
Setting Link Mode#
Setting Link Mode On#
documentView.setLinkModeOn()
documentView.setLinkModeOn();
Setting Link Mode Off#
documentView.setLinkModeOff()
documentView.setLinkModeOff();
Deleting Annotations#
Essentially all annotations are treated the same as simply selections once they have been selected by a user. This selection can then be removed by calling the deleteSelection()
method against the DocumentView
instance.
import com.artifex.sonui.editor.DocumentView
fun deleteDocumentSelection(documentView:DocumentView) {
documentView.deleteSelection()
}
import com.artifex.sonui.editor.DocumentView;
public void deleteDocumentSelection(documentView:DocumentView) {
documentView.deleteSelection();
}
Note
Without an annotation being currently selected in your document view calling deleteSelection()
will have no effect.