Hello,
I am a bit confused ... why are there so many TextField types?
com.cete.dynamicpdf.forms.TextField
com.cete.dynamicpdf.merger.forms.PdfTextField
com.cete.dynamicpdf.pageelements.forms.TextField
I spend lot of time figuring out which one is the right one in each use-case. They have no inheritance relationship, no clone concept so I can not just take one instance from an existing PDF document and copy the exact same TextField into a new PDF documetn but instead I have to write lot of boilerplate code for that?
Am I missing anything?
Thanks in advance,
Best regards,
Giovanni
why there are so many TextFields?
Re: why there are so many TextFields?
Support · Mar 3, 2010Hello Giovanni,
The "com.cete.dynamicpdf.pageelements.forms.TextField" will be used when adding a new form field to a PDF document. You can add this field to the page elements.
MyPage.getElements().add( textField );
You will get the "com.cete.dynamicpdf.merger.forms.PdfTextField" when using the PdfDocument object. You can get the X, Y width and height etc properties of the field using this PdfFormField. You can also call the CreateLabel method which adds a label in place of the field.
PdfDocument pdf = new PdfDocument( filePath );
MergeDocument document = new MergeDocument( pdf );
pdf.getForm().getFields().getPdfFormField("fieldName").getX( currPage ) //This is PdfFormField
You will get the "com.cete.dynamicpdf.forms.TextField" object from the merged PDF using the MergeDocument object.
//continuation from abouve code.
FormField field = document.getForm().getFields().getFormField("fieldName");
You can cast this FormField to its respective exact field type. You can refer to the FormFieldReader example for sample code.
If you want to create form fields in a PDF similar to the fields present in another PDF then you will have to read the field information using the PdfFormField class and then add new fields using the fields from com.cete.dynamicpdf.pageelements.forms.
Thanks,
ceTe Software Support Team.