Pdf - PdfAnnotationActions

18 Nov 202614 minutes to read

Represents actions associated with annotation events in a PDF document.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Pointer entered the annotation');');
// Assign the action to the annotation mouse-enter event
annotation.actions.mouseEnter = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Properties

Get gotFocus PdfAction

Gets the action performed when the annotation receives focus.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Annotation received focus');');
// Assign the action to the annotation focus event
annotation.actions.gotFocus = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Get the action assigned to the focus event
const gotFocusAction: PdfAction = annotation.actions.gotFocus;
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Set gotFocus void

Sets the action performed when the annotation receives focus.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation =
    new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction =
    new PdfJavaScriptAction('app.alert("Annotation received focus");');
// Assign the action to the annotation focus event
annotation.actions.gotFocus = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();
Parameter Type Description
value PdfAction The action to perform when the annotation receives focus.

Get lostFocus PdfAction

Gets the action performed when the annotation loses focus.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation =
    new PdfRectangleAnnotation(
        { x: 20, y: 20, width: 150, height: 60 }
    );
// Create a JavaScript action
const action: PdfJavaScriptAction =
    new PdfJavaScriptAction(
        'app.alert('Annotation lost focus');'
    );
// Assign the action to the annotation focus-out event
annotation.actions.lostFocus = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Get the action assigned to the focus-out event
const lostFocusAction: PdfAction =
    annotation.actions.lostFocus;
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Set lostFocus void

Sets the action performed when the annotation loses focus.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation =
    new PdfRectangleAnnotation(
        { x: 20, y: 20, width: 150, height: 60 }
    );
// Create a JavaScript action
const action: PdfJavaScriptAction =
    new PdfJavaScriptAction(
        'app.alert('Annotation lost focus');'
    );
// Assign the action to the annotation focus-out event
annotation.actions.lostFocus = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();
Parameter Type Description
value PdfAction The action to perform when the annotation loses focus.

Get mouseDown PdfAction

Gets the action performed when the mouse button is pressed within the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert("Mouse button pressed");');
// Assign the action to the annotation mouse-down event
annotation.actions.mouseDown = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Get the action assigned to the mouse-down event
const mouseDownAction: PdfAction = annotation.actions.mouseDown;
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Set mouseDown void

Sets the action performed when the mouse button is pressed within the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert("Mouse button pressed");');
// Assign the action to the annotation mouse-down event
annotation.actions.mouseDown = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();
Parameter Type Description
value PdfAction The action to perform when the mouse button is pressed.

Get mouseEnter PdfAction

Gets the action performed when the cursor enters the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Pointer entered the annotation');');
// Assign the action to the annotation mouse-enter event
annotation.actions.mouseEnter = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Get the action assigned to the mouse-enter event
const mouseEnterAction: PdfAction = annotation.actions.mouseEnter;
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Set mouseEnter void

Sets the action performed when the cursor enters the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Pointer entered the annotation');');
// Assign the action to the annotation mouse-enter event
annotation.actions.mouseEnter = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();
Parameter Type Description
value PdfAction The action to perform when the cursor enters the annotation.

Get mouseLeave PdfAction

Gets the action performed when the cursor leaves the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Pointer left the annotation');');
// Assign the action to the annotation mouse-leave event
annotation.actions.mouseLeave = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Get the action assigned to the mouse-leave event
const mouseLeaveAction: PdfAction = annotation.actions.mouseLeave;
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Set mouseLeave void

Sets the action performed when the cursor leaves the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Pointer left the annotation');');
// Assign the action to the annotation mouse-leave event
annotation.actions.mouseLeave = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();
Parameter Type Description
value PdfAction The action to perform when the cursor leaves the annotation.

Get mouseUp PdfAction

Gets the action performed when the mouse button is released within the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Mouse button released');');
// Assign the action to the annotation mouse-up event
annotation.actions.mouseUp = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Get the action assigned to the mouse-up event
const mouseUpAction: PdfAction = annotation.actions.mouseUp;
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();

Set mouseUp void

Sets the action performed when the mouse button is released within the annotation.

// Create a new PDF document
const document: PdfDocument = new PdfDocument();
// Add a page to the document
const page: PdfPage = document.addPage();
// Create a rectangle annotation
const annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 20, y: 20, width: 150, height: 60 });
// Create a JavaScript action
const action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert('Mouse button released');');
// Assign the action to the annotation mouse-up event
annotation.actions.mouseUp = action;
// Add the annotation to the page
page.annotations.add(annotation);
// Save the PDF document
document.save('output.pdf');
// Destroy the PDF document
document.destroy();
Parameter Type Description
value PdfAction The action to perform when the mouse button is released.