Skip to content

modern-pdf-lib


modern-pdf-lib / PdfAnnotation

Class: PdfAnnotation

Defined in: src/annotation/pdfAnnotation.ts:225

Base class for all PDF annotations.

Wraps a PdfDict representing the annotation dictionary. Subclasses add type-specific getters/setters.

Extended by

Constructors

Constructor

new PdfAnnotation(type, dict): PdfAnnotation

Defined in: src/annotation/pdfAnnotation.ts:232

Parameters

type

AnnotationType

dict

PdfDict

Returns

PdfAnnotation

Properties

annotationType

readonly annotationType: AnnotationType

Defined in: src/annotation/pdfAnnotation.ts:227

The annotation subtype.


dict

protected dict: PdfDict

Defined in: src/annotation/pdfAnnotation.ts:230

The underlying annotation dictionary.

Methods

generateAppearance()

generateAppearance(): PdfStream | undefined

Defined in: src/annotation/pdfAnnotation.ts:440

Generate an appearance stream for this annotation.

The base implementation returns undefined. Subclasses override to produce proper visual appearance.

Returns

PdfStream | undefined

A PdfStream for the /AP /N entry, or undefined.


getAuthor()

getAuthor(): string | undefined

Defined in: src/annotation/pdfAnnotation.ts:293

Get the author (PDF /T entry).

Returns

string | undefined


getColor()

getColor(): { b: number; g: number; r: number; } | undefined

Defined in: src/annotation/pdfAnnotation.ts:311

Get the annotation colour.

Returns

{ b: number; g: number; r: number; } | undefined


getContents()

getContents(): string | undefined

Defined in: src/annotation/pdfAnnotation.ts:275

Get the text contents (tooltip / popup text).

Returns

string | undefined


getOpacity()

getOpacity(): number

Defined in: src/annotation/pdfAnnotation.ts:333

Get the annotation opacity (0-1). Defaults to 1.

Returns

number


getRect()

getRect(): [number, number, number, number]

Defined in: src/annotation/pdfAnnotation.ts:251

Get the annotation rectangle [x1, y1, x2, y2].

Returns

[number, number, number, number]


getType()

getType(): AnnotationType

Defined in: src/annotation/pdfAnnotation.ts:242

Get the annotation subtype.

Returns

AnnotationType


isHidden()

isHidden(): boolean

Defined in: src/annotation/pdfAnnotation.ts:381

Whether the annotation is hidden.

Returns

boolean


isLocked()

isLocked(): boolean

Defined in: src/annotation/pdfAnnotation.ts:401

Whether the annotation is locked (cannot be moved/resized).

Returns

boolean


isPrintable()

isPrintable(): boolean

Defined in: src/annotation/pdfAnnotation.ts:391

Whether the annotation should be printed.

Returns

boolean


setAuthor()

setAuthor(author): void

Defined in: src/annotation/pdfAnnotation.ts:302

Set the author.

Parameters

author

string

Returns

void


setColor()

setColor(color): void

Defined in: src/annotation/pdfAnnotation.ts:324

Set the annotation colour.

Parameters

color
b

number

g

number

r

number

Returns

void


setContents()

setContents(contents): void

Defined in: src/annotation/pdfAnnotation.ts:284

Set the text contents.

Parameters

contents

string

Returns

void


setHidden()

setHidden(hidden): void

Defined in: src/annotation/pdfAnnotation.ts:386

Set the hidden flag.

Parameters

hidden

boolean

Returns

void


setLocked()

setLocked(locked): void

Defined in: src/annotation/pdfAnnotation.ts:406

Set the locked flag.

Parameters

locked

boolean

Returns

void


setOpacity()

setOpacity(opacity): void

Defined in: src/annotation/pdfAnnotation.ts:342

Set the annotation opacity.

Parameters

opacity

number

Returns

void


setPrintable()

setPrintable(printable): void

Defined in: src/annotation/pdfAnnotation.ts:396

Set the print flag.

Parameters

printable

boolean

Returns

void


setRect()

setRect(rect): void

Defined in: src/annotation/pdfAnnotation.ts:266

Set the annotation rectangle.

Parameters

rect

[number, number, number, number]

Returns

void


toDict()

toDict(registry): PdfDict

Defined in: src/annotation/pdfAnnotation.ts:420

Convert this annotation to a PdfDict suitable for embedding in a PDF.

Parameters

registry

PdfObjectRegistry

The object registry (used to register sub-objects).

Returns

PdfDict

The annotation dictionary.

Released under the MIT License.