Hello,
In acrobat you can set the format category of a text field to various things such as “number” and then set things like how many decimal places it should have and if there should be a separator comma (see attached image).
Is there a way to do the same with Aspose.PDF?
Hi Neil,
Thanks for contacting support.
As per my understanding, you need to change the form field type from text to number ? Please note that you can pass any acceptable values to fields inside PDF form. Please visit the following link for further details on Fill Form Fields in an Existing PDF File (Facades)
In case I have not properly understood your requirement, please share some further details.
Hi Nayyer,
What I am trying to do is create a PDF form, I would like to add a text field to the form and have it only accept numbers.
In acrobat you can set this by going into the field properties and setting the format category to be Number.
Is there a way to do this with Aspose.PDF?
I use the following code to add the text field:
Document doc = new Document();
Page page = doc.Pages.Add();
TextBoxField textBox = new TextBoxField() { Name = “MyNumberField”, PartialName = “MyNumberField”, Width = 80, Height = 20, Multiline = false };
page.Paragraphs.Add(textBox);
At the moment I am having to open the generated PDF in acrobat and set the properties for each field I want to only accept numbers, it would be a big help if I could do it in code instead.
Thanks,
Neil
Hi Neil,
Hi,
I want similar thing in Java PDF but instead of Number, I want to set it to date.
It is been 4 years, so I hope you guys have added that feature in your library.
Please guide me through that would be big help.
Thanks,
Darshit Patel
Regretfully, the earlier logged ticket is not yet resolved and Aspose.PDF for Java does not provide any built-in property for text box field to format it for specific value type. However, you can set JavaScript on validation of form fields using Aspose.PDF for Java and set field formatting using following code snippet:
Format TextBoxField for Date Value
Document doc = new Document();
Page page = doc.getPages().add();
TextBoxField tbf = new TextBoxField(page, new Rectangle(10, 800, 200, 750));
tbf.getCharacteristics().setBackground(Color.getCyan());
PdfAction action = new JavascriptAction("AFDate_FormatEx(\"mm/dd/yyyy\");");
tbf.getAnnotationActions().setOnValidate(action);
doc.getForm().add(tbf, 1);
doc.save(dataDir + "DateFormat.pdf");
Thanks for reply, is there any Field where format for Date can be set.
Regards,
Darshit Patel
In above shared code snippet, the Date Format is being set for text box field. Do you want to set it for different field?
I mean if there is any Field other than TextBoxField to set the Date format.
Thanks
The validation can be applied to Form Fields that take input from user e.g. DropDown, TextBox, etc. Furthermore, you can also verify in Adobe Reader for supported validations for every type of form fields and try to apply them using JavaScript Actions in Aspose.PDF. In case you face any issue, please let us know.
The issues you have found earlier (filed as PDFNET-34219) have been fixed in Aspose.PDF for .NET 22.3.