Pdf - PdfTargetRelation

18 Nov 20261 minute to read

Public enum to define the relationship of a PdfTargetDictionary entry to the current document.

// 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
let destination: PdfRemoteDestination = new PdfRemoteDestination();
destination.pageNumber = 0;
destination.mode = PdfDestinationMode.fitToPage;
// Create a target with a child relationship
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.text = 'Open embedded PDF';
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();
  • Child - Specifies that the target is a child of the current document.
  • Parent - Specifies that the target is the parent of the current document.