Articles in this section
Category / Section

How to add date field in a PDF form using C# and VB.NET

4 mins read

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can add date field in PDF form using C# and VB.NET.

Steps to add date field in PDF form programmatically:

  1. Create a new C# Windows Forms application project. Create new windows forms application
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. Install nuget packages
  3. Include the following namespaces in the Form1.Designer.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Interactive

 

  1. Use the following code snippet to add date field in PDF form.

C#

//Create a new PDF document
PdfDocument document = new PdfDocument();            
//Add a new page to PDF document
PdfPage page = document.Pages.Add();
//Create a text box for date field
PdfTextBoxField field = new PdfTextBoxField(page, "datePick");
//Set the text box properties
field.Bounds = new RectangleF(10, 10, 100, 20);
field.Actions.KeyPressed = new PdfJavaScriptAction("AFDate_KeystrokeEx(\"m/d/yy\")");
field.Actions.Format = new PdfJavaScriptAction("AFDate_FormatEx(\"m/d/yy\")");
//Add field to the form
document.Form.Fields.Add(field);
//Save the document
document.Save("Output.pdf");
//Close the document
document.Close(true);

 

VB.NET

'Create a new PDF document
Dim document As PdfDocument = New PdfDocument
'Add a new page to PDF document
Dim page As PdfPage = document.Pages.Add
'Create a text box for date field
Dim field As PdfTextBoxField = New PdfTextBoxField(page, "datePick")
'Set the text box properties
field.Bounds = New RectangleF(10, 10, 100, 20)
field.Actions.KeyPressed = New PdfJavaScriptAction("AFDate_KeystrokeEx(""m/d/yy"")")
field.Actions.Format = New PdfJavaScriptAction("AFDate_FormatEx(""m/d/yy"")")
'Add field to the form
document.Form.Fields.Add(field)
'Save the document
document.Save("Output.pdf")
'Close the document
document.Close(True)

 

A complete working sample can be downloaded from AddDateFieldPDFSample.zip.

By executing the program, you will get the PDF document as follows. Screenshot of output PDF file

Take a moment to peruse the documentation for working with forms, where you will find other options like filling, removing form fields in PDF document, and adding actions to form fields.

Refer here to explore the rich set of Syncfusion Essential PDF features.

An Online sample link to filling form fields into PDF document.

Note:

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.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied