Skip to content

modern-pdf-lib


modern-pdf-lib / PdfFileAttachmentAnnotation

Class: PdfFileAttachmentAnnotation

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:54

A file attachment annotation (subtype /FileAttachment).

Embeds a file directly in the annotation, rendered as a clickable icon on the page. When the user clicks the icon, the PDF viewer allows them to open or save the embedded file.

Extends

Constructors

Constructor

new PdfFileAttachmentAnnotation(dict): PdfFileAttachmentAnnotation

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:64

Parameters

dict

PdfDict

Returns

PdfFileAttachmentAnnotation

Overrides

PdfAnnotation.constructor

Properties

annotationType

readonly annotationType: AnnotationType

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

The annotation subtype.

Inherited from

PdfAnnotation.annotationType


dict

protected dict: PdfDict

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

The underlying annotation dictionary.

Inherited from

PdfAnnotation.dict

Methods

buildFileSpec()

buildFileSpec(registry): PdfDict

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:156

Build the file specification dictionary and register the embedded file stream. Call this before serializing the annotation.

Parameters

registry

PdfObjectRegistry

The document's object registry.

Returns

PdfDict

The annotation dict with /FS referencing the file.


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.

Inherited from

PdfAnnotation.generateAppearance


getAuthor()

getAuthor(): string | undefined

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

Get the author (PDF /T entry).

Returns

string | undefined

Inherited from

PdfAnnotation.getAuthor


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

Inherited from

PdfAnnotation.getColor


getContents()

getContents(): string | undefined

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

Get the text contents (tooltip / popup text).

Returns

string | undefined

Inherited from

PdfAnnotation.getContents


getFileName()

getFileName(): string | undefined

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:137

Get the filename, if set.

Returns

string | undefined


getIcon()

getIcon(): FileAttachmentIcon

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:116

Get the icon name. Defaults to 'GraphPushPin'.

Returns

FileAttachmentIcon


getOpacity()

getOpacity(): number

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

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

Returns

number

Inherited from

PdfAnnotation.getOpacity


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]

Inherited from

PdfAnnotation.getRect


getType()

getType(): AnnotationType

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

Get the annotation subtype.

Returns

AnnotationType

Inherited from

PdfAnnotation.getType


isHidden()

isHidden(): boolean

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

Whether the annotation is hidden.

Returns

boolean

Inherited from

PdfAnnotation.isHidden


isLocked()

isLocked(): boolean

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

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

Returns

boolean

Inherited from

PdfAnnotation.isLocked


isPrintable()

isPrintable(): boolean

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

Whether the annotation should be printed.

Returns

boolean

Inherited from

PdfAnnotation.isPrintable


setAuthor()

setAuthor(author): void

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

Set the author.

Parameters

author

string

Returns

void

Inherited from

PdfAnnotation.setAuthor


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

Inherited from

PdfAnnotation.setColor


setContents()

setContents(contents): void

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

Set the text contents.

Parameters

contents

string

Returns

void

Inherited from

PdfAnnotation.setContents


setHidden()

setHidden(hidden): void

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

Set the hidden flag.

Parameters

hidden

boolean

Returns

void

Inherited from

PdfAnnotation.setHidden


setIcon()

setIcon(icon): void

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:128

Set the icon name.

Parameters

icon

FileAttachmentIcon

Returns

void


setLocked()

setLocked(locked): void

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

Set the locked flag.

Parameters

locked

boolean

Returns

void

Inherited from

PdfAnnotation.setLocked


setOpacity()

setOpacity(opacity): void

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

Set the annotation opacity.

Parameters

opacity

number

Returns

void

Inherited from

PdfAnnotation.setOpacity


setPrintable()

setPrintable(printable): void

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

Set the print flag.

Parameters

printable

boolean

Returns

void

Inherited from

PdfAnnotation.setPrintable


setRect()

setRect(rect): void

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

Set the annotation rectangle.

Parameters

rect

[number, number, number, number]

Returns

void

Inherited from

PdfAnnotation.setRect


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.

Inherited from

PdfAnnotation.toDict


create()

static create(options): PdfFileAttachmentAnnotation

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:77

Create a new file attachment annotation.

Parameters

options

AnnotationOptions & object

Returns

PdfFileAttachmentAnnotation


fromDict()

static fromDict(dict, _resolver?): PdfFileAttachmentAnnotation

Defined in: src/annotation/types/fileAttachmentAnnotation.ts:104

Create a PdfFileAttachmentAnnotation from an existing dictionary.

Parameters

dict

PdfDict

_resolver?

(ref) => PdfObject | undefined

Returns

PdfFileAttachmentAnnotation

Released under the MIT License.