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()
    }
}

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

Line Color

To get/set the line color use the API as follows:

val color:Int = documentView.lineColor // getter
documentView.lineColor = 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()
    }
}

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()
}

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()
}

Note

Without an annotation being currently selected in your document view calling deleteSelection() will have no effect.

Author

To get/set the annotation author use the API as follows:

val author:String = documentView.author // getter
documentView?.author = "John Doe" // setter

This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software Inc., 39 Mesa Street, Suite 108A, San Francisco CA 94129, United States for further information.

Discord logo