How to add a mouse over action in the PDF textbox field using C# and VB.NET
Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can add a mouse over action in the PDF text box field using C# and VB.NET.
Steps to add a mouse over action in PDF text box field programmatically:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
- Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Graphics; using System.Drawing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Interactive Imports Syncfusion.Pdf.Graphics Imports System.Drawing
- Use the following code snippet to add a mouse over action in the PDF text box field.
C#
//Create a new PDF document PdfDocument document = new PdfDocument(); //Add a new page to the PDF document PdfPage page = document.Pages.Add(); //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16); //Draw the string page.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(10, 30)); //Create a text box field for name PdfTextBoxField textBoxField1 = new PdfTextBoxField(page, "Name"); textBoxField1.Bounds = new RectangleF(100, 30, 200, 20); textBoxField1.ToolTip = "Name"; //Add a mouse over action to textbox field textBoxField1.Actions.MouseEnter = new PdfJavaScriptAction("app.alert(\"Name cannot be blank and must be at least two letters\")"); document.Form.Fields.Add(textBoxField1); //Save the document document.Save("Form.pdf"); //close the document document.Close(true); //This will open the PDF file so, the result will be seen in default PDF viewer System.Diagnostics.Process.Start("Form.pdf");
VB.NET
'Create a new PDF document Dim document As PdfDocument = New PdfDocument() 'Add a new page to the PDF document Dim page As PdfPage = document.Pages.Add() 'Set the standard font Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 16) 'Draw the string page.Graphics.DrawString("Name", font, PdfBrushes.Black, New PointF(10, 30)) 'Create a text box field for name Dim textBoxField1 As PdfTextBoxField = New PdfTextBoxField(page, "Name") textBoxField1.Bounds = New RectangleF(100, 30, 200, 20) textBoxField1.ToolTip = "Name" 'Add a mouse over action to textbox field textBoxField1.Actions.MouseEnter = New PdfJavaScriptAction("app.alert(""Name cannot be blank and must be at least two letters"")") document.Form.Fields.Add(textBoxField1) 'Save the document document.Save("Form.pdf") 'Close the document document.Close(True) 'This will open the PDF file so, the result will be seen in default PDF viewer System.Diagnostics.Process.Start("Form.pdf")
A complete working sample can be downloaded from PdfSample.zip.
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation, where you can find other options like adding an action to the PDF, supported action types, adding an action to the bookmarks and features like interactive form and XFA form with code examples.
Refer here to explore the rich set of Syncfusion Essential PDF features.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.