Skip to main content
Version: Version 5 beta

Class: AnnotationManager

Class for managing annotations within a PDF document.

Extends

Implements

Constructors

new AnnotationManager()

new AnnotationManager(document): AnnotationManager

Parameters

document: Document

Returns

AnnotationManager

Overrides

EventEmitter.constructor

Methods

add()

add(annotation)

add(annotation): Promise<void>

Adds a single annotation to the document.

Parameters

annotation: Annotation

The annotation to be added.

Returns

Promise<void>

add(annotations)

add(annotations): Promise<void>

Adds multiple annotations to the document.

Parameters

annotations: Annotation[]

An array of annotations to be added.

Returns

Promise<void>


addEventListener()

addEventListener<K>(type, listener): void

Register a function that will be called whenever the specified event is delivered.

Type Parameters

K extends keyof AnnotationManagerEventMap

A generic type representing the key of the event type.

Parameters

type: K

String representing the event type to listen for.

listener

The function that will be executed when an event of the specified type occurs.

Returns

void

Inherited from

EventEmitter.addEventListener


bringToBack()

bringToBack(annotation): void

Experimental

Brings the specified annotation to the back, making it appear below other annotations.

Parameters

annotation: Annotation

The annotation to bring to the back.

Returns

void


bringToFront()

bringToFront(annotation): void

Experimental

Brings the specified annotation to the front, making it appear above other annotations.

Parameters

annotation: Annotation

The annotation to bring to the front.

Returns

void


copy()

copy(annotation): void

Experimental

Creates a copy of the specified annotation.

Parameters

annotation: Annotation

The annotation to be copied.

Returns

void


delete()

delete(annotation)

delete(annotation): Promise<void>

Deletes a single annotation from the document.

Parameters

annotation: Annotation

The annotation to be deleted.

Returns

Promise<void>

delete(annotations)

delete(annotations): Promise<void>

Deletes multiple annotations from the document.

Parameters

annotations: Annotation[]

An array of annotations to be deleted.

Returns

Promise<void>

delete(annotationId)

delete(annotationId): Promise<void>

Experimental

Deletes an annotation by its ID from the document.

Parameters

annotationId: string

The ID of the annotation to be deleted.

Returns

Promise<void>


dispatchEvent()

dispatchEvent<K>(type, args): void

Dispatches an event to all registered listeners.

Type Parameters

K extends keyof AnnotationManagerEventMap

A generic type representing the key of the event type.

Parameters

type: K

String representing the event type to dispatch.

args: Parameters<AnnotationManagerEventMap[K]>

The data associated with the event.

Returns

void

Inherited from

EventEmitter.dispatchEvent


dispose()

dispose(): void

Disposes of the object, releasing any resources it holds.

The dispose method is responsible for performing cleanup operations and releasing any resources acquired by the object. Once an object is disposed, it should not be used, and attempts to do so may result in undefined behavior.

Returns

void

Implementation of

Disposable.dispose


getAll()

getAll(): Promise<Annotation[]>

Retrieves a list of all annotations in the document.

Returns

Promise<Annotation[]>

An array containing all the annotations.


getAllOnPage()

getAllOnPage(pageNumber): Promise<Annotation[]>

Retrieves annotations on a specific page.

Parameters

pageNumber: number

The page number to retrieve annotations from.

Returns

Promise<Annotation[]>

An array containing all the annotations on a specific page.


getAnnotationsOnPoint()

getAnnotationsOnPoint(pageNumber, point, onlySelectable): Promise<Annotation[]>

Gets all annotations on a point on the page.

Parameters

pageNumber: number

The page number to retrieve annotations from.

point: PdfPoint

The PDF point on the current page.

onlySelectable: boolean

Only return annotations which can be selected.

Returns

Promise<Annotation[]>

An array containing all the annotations on point.


getById()

getById(annotationId): Annotation

Experimental

Retrieves an annotation by its ID from the document.

Parameters

annotationId: string

The ID of the annotation to retrieve.

Returns

Annotation

The retrieved annotation.


getTextStampAspectRatio()

getTextStampAspectRatio(text): Promise<number>

Calculates the aspect ratio of a custom text stamp based on the provided text.

This method retrieves the width-to-height ratio of a text stamp, which can be used to correctly scale the stamp when adding it to a document.

Parameters

text: string

The text content of the custom text stamp for which the aspect ratio is to be calculated.

Returns

Promise<number>

A promise that resolves to the aspect ratio (width divided by height) of the custom text stamp.


hide()

hide(annotation)

hide(annotation): Promise<void>

Hides the specified annotation, making it invisible within the document.

Parameters

annotation: Annotation

The annotation to be hidden.

Returns

Promise<void>

hide(annotations)

hide(annotations): Promise<void>

Experimental

Hides multiple annotations, making them invisible within the document.

Parameters

annotations: Annotation[]

An array of annotations to be hidden.

Returns

Promise<void>


removeAllListeners()

removeAllListeners<K>(type): void

Remove all listeners for a given event.

Type Parameters

K extends keyof AnnotationManagerEventMap

A generic type representing the key of the event type.

Parameters

type: K

String representing the event for which to remove all listeners.

Returns

void

Inherited from

EventEmitter.removeAllListeners


removeEventListener()

removeEventListener<K>(type, listener): void

Removes an event listener previously registered with addEventListener.

Type Parameters

K extends keyof AnnotationManagerEventMap

A generic type representing the key of the event type.

Parameters

type: K

String representing the event for which to remove an event listener.

listener

The event listener function of the event handler to remove from the event target.

Returns

void

Inherited from

EventEmitter.removeEventListener


update()

update(annotation)

update(annotation): Promise<void>

Updates a single annotation in the document.

Parameters

annotation: Annotation

The annotation to be updated.

Returns

Promise<void>

update(annotations)

update(annotations): Promise<void>

Updates multiple annotations in the document.

Parameters

annotations: Annotation[]

An array of annotations to be updated.

Returns

Promise<void>