Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Mon Jul 01, 2019 2:01 pm
I am trying to create an input field to collect date time information. What I seem to be finding is that the PdfDateTimeField is not included in the fields collection and I have been unable to use it to show my date time field. Is there a proper method for adding a Date Time field as an input field to my PDF file?
-

[email protected]
-
- Posts: 1
- Joined: Thu Jun 27, 2019 6:08 pm
Tue Jul 02, 2019 6:57 am
Hello,
Thanks for your inquiry.
Please refer to the following sample code to add a Date Time field as an input field to a PDF file. If there is any question, please provide your input PDF file as well as your desired effect of output to help us further investigate it. You could send them to us via email (
[email protected]).
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"test.pdf");
doc.AllowCreateForm = true;
PdfPageBase page = doc.Pages[0];
//add TextBox field
PdfTextBoxField textBox = new PdfTextBoxField(page, "DateTimeField")
{
//the settings for the field
BorderColor = Color.Green,
Location = new PointF(50, 50),
Size = new SizeF(60, 20),
TextAlignment = PdfTextAlignment.Center,
ToolTip = "Enter a date time like 'm/d/yy HH:MM'."
};
//add js action;
string jsAction = PdfJavaScript.GetDateFormatString("m/d/yy HH:MM");
PdfJavaScriptAction jsActionDateTime = new PdfJavaScriptAction(jsAction);
textBox.Actions.Format = jsActionDateTime;
doc.Form.Fields.Add(textBox);
doc.SaveToFile("result.pdf", Spire.Pdf.FileFormat.PDF);
Sincerely,
Lisa
E-iceblue support team
-


Lisa.Li
-
- Posts: 1536
- Joined: Wed Apr 25, 2018 3:20 am
Tue Jul 09, 2019 9:59 am
Hello,
Greetings from E-iceblue.
Did my code help you? Thanks in advance for your valuable feedback and time.
Sincerely,
Lisa
E-iceblue support team
-


Lisa.Li
-
- Posts: 1536
- Joined: Wed Apr 25, 2018 3:20 am