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 delete method on the PDFPage class.

EXAMPLE

page.delete(annotation)

Annotation Types#

For annotation creation the list of supported types is as follows:

Annotation types

Name

Creation supported

Notes

Text

Yes

This is what a “Note” style annotation looks like.

Link

Yes

FreeText

Yes

Not to be confused with the “Text” type, “FreeText” is displayed straight on the PDF page.

Square

Yes

Circle

Yes

Line

Yes

Polygon

Yes

PolyLine

Yes

Highlight

Yes

Underline

Yes

Squiggly

Yes

StrikeOut

Yes

Redact

Yes

Stamp

Yes

Caret

Yes

Ink

Yes

FileAttachment

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#

Position and Size#

Author#

Getting/Setting Annotation Date#

Graphics and Drawing#

Obtain a Pixmap from an annotation

Icon properties

Color and opacity


Code samples

Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:

import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"