Class: JavaScriptAction

PSPDFKit.Actions.JavaScriptAction

PDF action to run arbitrary JavaScript.

It is an Immutable.Record and thus can be updated using set(key, value), for example: action.set("script", "alert(...)");.

Constructor

new PSPDFKit.Actions.JavaScriptAction(args)

Run arbitrary JavaScript.

Parameters:
Name Type Description
args object
Examples

Create a new JavaScriptAction

const action = new PSPDFKit.Actions.JavaScriptAction({
  script: "alert(...)"
});

Create a button to import a image using a JavaScriptAction

const widget = new PSPDFKit.Annotations.WidgetAnnotation({
  id: PSPDFKit.generateInstantId(),
  pageIndex: 0,
  formFieldName: "buttonIcon",
  boundingBox: new PSPDFKit.Geometry.Rect({
    left: 100,
    top: 200,
    width: 100,
    height: 100
  }),
  action: new PSPDFKit.Actions.JavaScriptAction({
    script: "event.target.buttonImportIcon()"
  }),
  borderWidth: 0
});
const formField = new PSPDFKit.FormFields.ButtonFormField({
  name: "buttonIcon",
  annotationIds: PSPDFKit.Immutable.List([widget.id])
});
await instance.create([widget, formField]);

Extends

Members




Members

script: string

The JavaScript to run.

Type:
  • string

subActions: PSPDFKit.Immutable.List.<Action>

Actions can be chained by adding them to this immutable List.

Type: