Nutrient Web SDK

Class 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(...)");.

Class

Example

Create a new JavaScriptAction

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

Create a button to import a image using a JavaScriptAction

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

Hierarchy

JavaScriptActionDataActionJavaScriptAction

Constructors

Properties

string

The JavaScript to run.

subActions

Optional

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

Immutable Record API

24
  • Returns

    this

    See Also

    • Map#asImmutable

  • Returns

    this

    See Also

    • Map#asMutable

  • Returns a new instance of this Record type with all values set to their default values.

    Returns

    this
  • Returns a new instance of this Record type with the value for the specific key set to its default value.

    Type Parameters

    Kextends "subActions"

    Parameters

    keyK

    Returns

    this
  • Parameters

    otherunknown

    Returns

    boolean
  • Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.

    If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.

    Type Parameters

    Kextends "subActions"

    Parameters

    keyK

    Returns

    { … }[K]
  • Parameters

    keyPathIterable<unknown>
    notSetValueunknown
    Optional

    Returns

    unknown
  • Parameters

    keyunknown

    Returns

    boolean
  • Parameters

    ...collections
    (Iterable<[string, unknown], any, any> | Partial<{ … }>)[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collections
    (Iterable<[string, unknown], any, any> | Partial<{ … }>)[]

    Returns

    this
  • Parameters

    merger(previous?: unknown, next?: unknown, key?: string) => unknown
    ...collections
    (Iterable<[string, unknown], any, any> | Partial<{ … }>)[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collections
    (Iterable<[string, unknown], any, any> | Partial<{ … }>)[]

    Returns

    this
  • Parameters

    merger(previous?: unknown, next?: unknown, key?: string) => unknown
    ...collections
    (Iterable<[string, unknown], any, any> | Partial<{ … }>)[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    valueunknown

    Returns

    this
  • Returns

    Keyed<string, unknown>
  • Parameters

    keyPathIterable<unknown>
    notSetValueunknown
    updater(value: unknown) => unknown

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    updater(value: unknown) => unknown

    Returns

    this
  • Note: Not all methods can be used on a mutable collection or within withMutations! Only set may be used mutatively.

    Parameters

    mutator(mutable: this) => unknown

    Returns

    this

    See Also

    • Map#withMutations