Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

JavaScript Actions

As of Q4 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:

Class Collection Type
Link* ActionCollection
BookmarkItem* ActionCollection
Widget WidgetActionCollection
FormField FormFieldActionCollection
RadFixedDocument DocumentActionCollection
RadFixedPage PageActionCollection

* 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


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

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

   TextBoxField field2 = new TextBoxField("Field2");
   VariableContentWidget widget2 = field2.Widgets.AddWidget();
   widget2.Rect = new Rect(new Point(0, 50), new Size(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(new Point(0, 100), new Size(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);

See Also

In this article