Skip to content

Commit 9c801ed

Browse files
committed
1004110-ug: Added a date field to a PDF form
1 parent 87be45a commit 9c801ed

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Document-Processing/PDF/PDF-Library/NET/Working-with-forms.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,6 +4504,94 @@ document.Close(True)
45044504

45054505
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Forms/Export_checkbox_values/.NET).
45064506

4507+
## Add a date field to a PDF form
4508+
4509+
This section explains how to add a date text box field to a PDF form using the Syncfusion PDF library. The field is prefilled with a sample date and uses JavaScript-based formatting to enforce the date format, validate input, and automatically format user entries.
4510+
4511+
The following code example illustrates how to add a date field to a PDF form.
4512+
4513+
{% tabs %}
4514+
{% highlight c# tabtitle="C# [Cross-platform]" %}
4515+
4516+
using Syncfusion.Drawing;
4517+
using Syncfusion.Pdf;
4518+
using Syncfusion.Pdf.Interactive;
4519+
4520+
// Create a new PDF document
4521+
using (PdfDocument pdfDocument = new PdfDocument())
4522+
{
4523+
// Add a new page to the PDF document
4524+
PdfPage pdfPage = pdfDocument.Pages.Add();
4525+
// Create a text box field for entering the name
4526+
PdfTextBoxField nameField = new PdfTextBoxField(pdfPage, "DateField");
4527+
nameField.Bounds = new RectangleF(10, 40, 200, 20);
4528+
nameField.ToolTip = "Date";
4529+
nameField.Text = "12/01/1995";
4530+
//Set the scriptAction to submitButton
4531+
nameField.Actions.KeyPressed = new PdfJavaScriptAction("AFDate_KeystrokeEx(\"m/d/yy\")");
4532+
nameField.Actions.Format = new PdfJavaScriptAction("AFDate_FormatEx(\"m/d/yy\")");
4533+
nameField.Actions.Validate = new PdfJavaScriptAction("AFDate_Validate(\"m/d/yy\")");
4534+
// Add the field to the form
4535+
pdfDocument.Form.Fields.Add(nameField);
4536+
// Save the PDF document
4537+
pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
4538+
}
4539+
{% endhighlight %}
4540+
{% highlight c# tabtitle="C# [Windows-specific]" %}
4541+
4542+
using System.Drawing;
4543+
using Syncfusion.Pdf;
4544+
using Syncfusion.Pdf.Interactive;
4545+
4546+
// Create a new PDF document
4547+
using (PdfDocument pdfDocument = new PdfDocument())
4548+
{
4549+
// Add a new page to the PDF document
4550+
PdfPage pdfPage = pdfDocument.Pages.Add();
4551+
// Create a text box field for entering the name
4552+
PdfTextBoxField nameField = new PdfTextBoxField(pdfPage, "DateField");
4553+
nameField.Bounds = new RectangleF(10, 40, 200, 20);
4554+
nameField.ToolTip = "Date";
4555+
nameField.Text = "12/01/1995";
4556+
//Set the scriptAction to submitButton
4557+
nameField.Actions.KeyPressed = new PdfJavaScriptAction("AFDate_KeystrokeEx(\"m/d/yy\")");
4558+
nameField.Actions.Format = new PdfJavaScriptAction("AFDate_FormatEx(\"m/d/yy\")");
4559+
nameField.Actions.Validate = new PdfJavaScriptAction("AFDate_Validate(\"m/d/yy\")");
4560+
// Add the field to the form
4561+
pdfDocument.Form.Fields.Add(nameField);
4562+
// Save the PDF document
4563+
pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
4564+
}
4565+
{% endhighlight %}
4566+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
4567+
4568+
Imports System.Drawing
4569+
Imports Syncfusion.Pdf
4570+
Imports Syncfusion.Pdf.Interactive
4571+
4572+
' Create a new PDF document
4573+
Using pdfDocument As New PdfDocument()
4574+
' Add a new page to the PDF document
4575+
Dim pdfPage As PdfPage = pdfDocument.Pages.Add()
4576+
' Create a text box field for entering the name
4577+
Dim nameField As New PdfTextBoxField(pdfPage, "DateField")
4578+
nameField.Bounds = New RectangleF(10, 40, 200, 20)
4579+
nameField.ToolTip = "Date"
4580+
nameField.Text = "12/01/1995"
4581+
' Set the scriptAction to submitButton
4582+
nameField.Actions.KeyPressed = New PdfJavaScriptAction("AFDate_KeystrokeEx(""m/d/yy"")")
4583+
nameField.Actions.Format = New PdfJavaScriptAction("AFDate_FormatEx(""m/d/yy"")")
4584+
nameField.Actions.Validate = New PdfJavaScriptAction("AFDate_Validate(""m/d/yy"")")
4585+
' Add the field to the form
4586+
pdfDocument.Form.Fields.Add(nameField)
4587+
' Save the PDF document
4588+
pdfDocument.Save(Path.GetFullPath("Output/Output.pdf"))
4589+
End Using
4590+
{% endhighlight %}
4591+
{% endtabs %}
4592+
4593+
You can download a complete working sample from GitHub.
4594+
45074595
## Unified radio button selection
45084596

45094597
The essential<sup>&reg;</sup> PDF allows radio buttons within the same group that have identical export values to be selected or deselected simultaneously.

0 commit comments

Comments
 (0)