Reputation: 89
I am getting form fields from the PDF document but I did not see any method for getting form field format ForExample there are multiple text form fields in my document including Number field, Date field, Percentage field. Is there any way to get field format type in itext7
Upvotes: 0
Views: 1395
Reputation: 89
@Uladzimir Asipchuk /TU dictionary contains ToolTip value. Format value is contained in /AA >> /K dictionary in PDF structure. However I have extracted the JS Method after some tries and exploring the PDF structure through Pre-Flight. The following code snippet give the associated JSMethod if any:
PdfDictionary additionalActions = formField.GetAdditionalAction();
if (additionalActions != null)
{
PdfDictionary formatDictionary = additionalActions.GetAsDictionary(PdfName.K);
PdfString jsMethod = formatDictionary.GetAsString(PdfName.JS);
string fieldJsMethod = jsMethod.GetValue();
}
Upvotes: 1
Reputation: 2478
I created a pdf via Adobe (as you suggested) and I indeed was able to set the "format" of a text field as Date
, Number
, Percentage
, Email
,..
Then I opened the resultant pdf in RUPS (an utility program used to open the pdf's tree) and investigated it.
It turned out that Adobe sets the "format" which you want to get as a /TU
value of the field's dictionary. For example, for Percentage
it's percentfield
and for Email
- emailfield
.
Now the only thing you need to find the "format" of your fieeld is to get the value of /TU
entry of your field:
field.getValue().getPdfObject().get(PdfName.TU)
Upvotes: 0