Pdf - PdfTargetDictionary

18 Nov 20269 minutes to read

Represents a target used to locate an embedded PDF document or annotation.

// Create an embedded PDF document
let embeddedDocument: PdfDocument = new PdfDocument();
embeddedDocument.addPage();
let embeddedData: Uint8Array = embeddedDocument.save();
embeddedDocument.destroy();
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
document.attachments.add(new PdfAttachment(embeddedData, 'embedded.pdf'));
// Create the embedded PDF destination and target
let destination: PdfRemoteDestination = new PdfRemoteDestination();
destination.pageNumber = 0;
destination.mode = PdfDestinationMode.fitToPage;
let target: PdfTargetDictionary = new PdfTargetDictionary(PdfTargetRelation.Child, 'embedded.pdf');
// Create an embedded GoTo action
let action: PdfEmbeddedGoToAction = new PdfEmbeddedGoToAction(destination, undefined, target);
// Create a button and assign the action
let field: PdfButtonField = new PdfButtonField(
    page, 'EmbeddedGoTo', { x: 20, y: 20, width: 120, height: 30 }
);
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Properties

Get annotationIndex number

Gets the zero-based annotation index associated with the target.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action and target annotation index
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
let annotationIndex: number = action.target.annotationIndex;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set annotationIndex void

Sets the zero-based annotation index associated with the target.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
// Set the target annotation index
action.target.annotationIndex = 0;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value number The zero-based annotation index to associate with the target.

Get name string

Gets the name used to locate the target document.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action and target name
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
let name: string = action.target.name;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set name void

Sets the name used to locate the target document.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
// Set the target name
action.target.name = 'updated.pdf';
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value string The name used to locate the target document.

Get pageNumber number

Gets the zero-based page number associated with the target.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action and target page number
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
let pageNumber: number = action.target.pageNumber;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set pageNumber void

Sets the zero-based page number associated with the target.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
// Set the target page number
action.target.pageNumber = 0;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value number The zero-based page number to associate with the target.

Get relation PdfTargetRelation

Gets the relationship between the current document and the target.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action and target relationship
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
let relation: PdfTargetRelation = action.target.relation;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set relation void

Sets the relationship between the current document and the target.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
// Set the target relationship
action.target.relation = PdfTargetRelation.Child;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value PdfTargetRelation The relationship between the current document and the target.

Get target PdfTargetDictionary

Gets the nested target used to locate an embedded document.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action and nested target
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
let target: PdfTargetDictionary = action.target.target;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set target void

Sets the nested target used to locate an embedded document.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the embedded GoTo button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the embedded GoTo action
let action: PdfEmbeddedGoToAction = field.actions.mouseUp as PdfEmbeddedGoToAction;
// Create and set a nested target
let target: PdfTargetDictionary = new PdfTargetDictionary(PdfTargetRelation.Child, 'child.pdf');
action.target.target = target;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value PdfTargetDictionary The nested target used to locate an embedded document.