New to Telerik Document ProcessingStart a free 30-day trial

JavaScript Actions

Updated on Jun 3, 2026
Minimum VersionQ4 2024

RadPdfProcessing supports:

  • JavaScript actions associated with documents, pages, form fields, and other elements.
  • Event-triggered actions that execute after a certain event in the respective viewer (for example, RadPdfViewer, Adobe Acrobat, or a web browser) is triggered.

The JavaScriptAction class represents JavaScript actions and stores the JS content as plain text in its public Script property.

PdfProcessing JS Actions Overview diagram

You can add JS actions 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 TextBoxField instances where the third field calculates the sum of the values entered in the first two widgets:

JS Action Sum FormField result showing automatic calculation

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 MergedJavaScriptNameResolving event fires when resolving conflicts between JavaScript names while merging RadFixedDocument instances.

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

See Also