New to Telerik Document ProcessingStart a free 30-day trial

JavaScript Actions

Updated on Feb 19, 2026
Minimum VersionQ4 2024

RadPdfProcessing provides support for:

  • JavaScript actions associated with documents, pages, form fields, etc.
  • Event triggered actions - represent actions that can be executed after a certain event in the respective viewer (e.g. RadPdfViewer, Adobe or a web browser) is triggerred.

JavaScript Actions are represented by the JavaScriptAction class storing in its public Script property the JS content as plain text.

PdfProcessing JS Actions Overview

JS actions can be added by using the public Actions property of the following classes:

* The existing Action property is obsolete.

Adding a JavaScript Action to a TextBoxField

The following example demonstrates how to create a PDF document with three TextBoxFields where the third field calculates the sum of the values entered in the first two widgets:

JS Action Sum FormField

c#
RadFixedDocument document = new RadFixedDocument();
document.Pages.AddPage();

TextBoxField field1 = new TextBoxField("Field1");
VariableContentWidget widget1 = field1.Widgets.AddWidget();
widget1.Rect = new Rect(0, 0, 150, 30);

TextBoxField field2 = new TextBoxField("Field2");
VariableContentWidget widget2 = field2.Widgets.AddWidget();
widget2.Rect = new Rect(0, 50, 150, 30);

TextBoxField totalField = new TextBoxField("Total");
totalField.IsReadOnly = true;
totalField.Actions.Calculate = new Telerik.Windows.Documents.Fixed.Model.Actions.JavaScriptAction
    ("AFSimple_Calculate(\"SUM\", new Array (\"Field1\", \"Field2\"));");
VariableContentWidget totalWidget = totalField.Widgets.AddWidget();
totalWidget.Rect = new Rect(0, 100, 150, 30);

document.AcroForm.FormFields.Add(field1);
document.AcroForm.FormFields.Add(field2);
document.AcroForm.FormFields.Add(totalField);
document.Pages[0].Annotations.Add(widget1);
document.Pages[0].Annotations.Add(widget2);
document.Pages[0].Annotations.Add(totalWidget);

Using the MergedJavaScriptNameResolving Event

The event is fired when trying to resolve conflicts between the JavaScript names while merging RadFixedDocument instances.

c#
document.MergedJavaScriptNameResolving += (sender, e) =>
{
    if (e.UsedNames.Contains(e.Name))
    {
        e.NewName = e.Name + "1";
    }
};

See Also