Get, create, or edit PDF interactive form actions in C# and VB.NET

PDF .Net supports the creation, deletion, and editing of interactive form field actions.

Interactive form actions are represented by the following classes in PDF .Net: PdfResetFormAction, PdfImportFormDataAction, and PdfSubmitFormAction.

The following example shows how to edit and create a button with interactive form field actions and how to customize the appearance of the button.

Complete code

using System;
using SautinSoft.Pdf;
using System.IO;

class Program
{
	static void Main()
	{
		// This property is necessary only for licensed version.
		//SautinSoft.Pdf.Serial = "XXXXXXXXXXX";

		using (var document = PdfDocument.Load("Form.pdf"))
		{
			// Update the action and label of the 'ResetButton' field so that only the 'Notes' field is reset.
			var resetButtonField = (PdfButtonField)document.Form.Fields["ResetButton"];
			var resetFormAction = (PdfResetFormAction)resetButtonField.Actions[0];

			resetFormAction.SelectedFields.Excluded = false;
			resetFormAction.SelectedFields.Add("Notes");
			resetButtonField.Appearance.Label = "Reset Notes";

			var bounds = resetButtonField.Bounds;

			// Add an 'ImportButton' field with a label and icon that imports field values from the FDF (Forms Data Format) file.
			var importButtonField = document.Form.Fields.AddButton(document.Pages[0], bounds.Left, bounds.Bottom - 80, 150, 60);
			importButtonField.Name = "ImportButton";
			importButtonField.Actions.AddImportFormData("FormData.fdf");

			var appearance = importButtonField.Appearance;
			appearance.LabelPlacement = PdfTextPlacement.TextAboveIcon;
			appearance.Label = "Import Data";

			var icon = new PdfForm(document, new PdfSize(128, 128));
			icon.Content.BeginEdit();
			icon.Content.DrawImage(PdfImage.Load("import.png"), new PdfPoint(0, 0), new PdfSize(128, 128));
			icon.Content.EndEdit();
			appearance.Icon = icon;

			bounds = importButtonField.Bounds;

			// Add a 'SubmitButton' field with an icon that submits all field values to the URL in XFDF (XML Forms Data Format) format.
			var submitButtonField = document.Form.Fields.AddButton(document.Pages[0], bounds.Left, bounds.Bottom - 60, 150, 40);
			submitButtonField.Name = "SubmitButton";

			var submitFormAction = submitButtonField.Actions.AddSubmitForm("https://www.sautinsoft.com/");
			submitFormAction.ExportFormat = PdfFormDataFormat.XFDF;
			submitFormAction.SelectedFields.All = true;

			appearance = submitButtonField.Appearance;
			appearance.LabelPlacement = PdfTextPlacement.IconOnly;

			icon = new PdfForm(document, new PdfSize(128, 128));
			icon.Content.BeginEdit();
			icon.Content.DrawImage(PdfImage.Load("submit.png"), new PdfPoint(0, 0), new PdfSize(128, 128));
			icon.Content.EndEdit();
			appearance.Icon = icon;

			document.Save("Form Actions.pdf");
		}
	}
}

            

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.