Getting Started#
Create an Annotation#
To create an annotation use the createAnnotation method on the PDFPage class.
For example, assuming you have acquired an instance of a PDFPage, to create a text annotation do the following:
EXAMPLE
let annotation = page.createAnnotation("Text")
Delete an Annotation#
To delete an annotation use the deleteAnnotation method on the PDFPage class.
EXAMPLE
page.deleteAnnotation(annotation)
Annotation Types#
For annotation creation the list of supported types is as follows:
Annotation types
Name |
Creation supported |
Notes |
|---|---|---|
Yes |
This is what a “Note” style annotation looks like. |
|
Yes |
||
Yes |
Not to be confused with the “Text” type, “FreeText” is displayed straight on the PDF page. |
|
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Yes |
||
Sound |
No |
|
Movie |
No |
|
Popup |
No |
|
RichMedia |
No |
|
Widget |
No |
|
Screen |
No |
|
PrinterMark |
No |
|
TrapNet |
No |
|
Watermark |
No |
|
3D |
No |
|
Projection |
No |
Note
Annotation types are also referred to as “subtypes”.
Get All Annotations for a Document#
The following code queries all the pages of a document to retrieve the annotations on each page.
EXAMPLE
let i = 0
while (i < document.countPages()) {
const page = document.loadPage(i)
const annots = page.getAnnotations()
console.log(`Page=${page}, Annotations=${annots}`)
i++
}
Common Annotation Methods#
The following list shows some of the most commonly used methods to work with annotations. This list is not exhaustive - see the PDFAnnotation for the full API.
Get the Annotation Type#
getType
Position and Size#
getBoundshasRectgetRectsetRect
Getting/Setting Annotation Date#
getCreationDatesetCreationDategetModificationDatesetModificationDate
Graphics and Drawing#
Obtain a Pixmap from an annotation
toPixmap
Icon properties
hasIcongetIconsetIcon
Color and opacity
getColorsetColorhasInteriorColorgetInteriorColorsetInteriorColorgetOpacitysetOpacity