PDF Annotations
Annotations
Annotations include allowing drawing, adding notes and highlighting text on a PDF document.
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();
}
}
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.
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
Note Mode
Depending on the mode the user will be able to add notes onto the document or not.
To turn on note mode call the setNoteModeOn()
method against your DocumentView
instance. To turn off note mode just call the corresponding setNoteModeOff()
method against your DocumentView
instance.
import com.artifex.sonui.editor.DocumentView
fun setDocumentNoteMode(documentView:DocumentView, enable:Boolean) {
if (enable) {
documentView.setNoteModeOn()
} else {
documentView.setNoteModeOff()
}
}
import com.artifex.sonui.editor.DocumentView;
public void setDocumentNoteMode(documentView:DocumentView, enable:Boolean) {
if (enable) {
documentView.setNoteModeOn();
} else {
documentView.setNoteModeOff();
}
}
Highlighting
In order to create a highlight annotation on some text in a PDF document, you must first have some text selected. Once selected call the highlightSelection()
method against your DocumentView
instance.
import com.artifex.sonui.editor.DocumentView
fun setDocumentHighlight(documentView:DocumentView) {
documentView.highlightSelection()
}
import com.artifex.sonui.editor.DocumentView;
public void setDocumentHighlight(documentView:DocumentView) {
documentView.highlightSelection();
}
Note
Without a text selection being present in your document view calling highlightSelection()
will have no effect.
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.