FormField size

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Merger for Java (v7)  /  FormField size

DynamicPDF Merger for Java (v7) Forum

 Apr 20 2016 1:17 PM
I'm retrieving an acroform field by name using the getFormField() function. I looked at the reference for FormField and didn't see what I need -- is there a way to retrieve the height and width of the FormField retrieved?

Thanks
 Apr 21 2016 12:00 PM
Posted by a ceTe Software moderator
Hello,

Yes, you can get the dimensions of the form fields in an existing PDF using DynamicPDF Merger for Java product. You will need to load the PDF using PdfDocument class, retrieve the form field dimensions using getWidth and getHeight methods of PdfFormField class. You can refer to the documentation on PdfFormField class members here. Below is the code sample.

            PdfDocument pdf = new PdfDocument("Path for an input PDF");
            MergeDocument document=new MergeDocument(pdf);
            //Getting Dimensions of the form field.
            float width= pdf.getForm().getFields().getPdfFormField("Full form field name").getWidth();
            float height = pdf.getForm().getFields().getPdfFormField("Full form field name ").getHeight();

Thanks,
ceTe Software Support Team.
 Apr 21 2016 1:11 PM
Support,

My getFormField() function is returning a FormField object (which does not seem to have a getWidth() and getHeight() functino), not a PdfFormField object which appears to.

 Apr 21 2016 4:42 PM
Posted by a ceTe Software moderator
Hello,

FormField object does not have getWidth() and getHeight() methods. getFormField() is not the correct method to retrieve the height and width of the form field present on a PDF.

You would need to use getPdfFormField() method which returns a PdfFormField object that has getHeight() and getWidth() methods you need.  In order to access getPdfFormField() method, you would need to create a PdfDocument object and then call getForm().getFields().getPdfFormField("Full form field name") as shown in the sample provided in our previous post.

Thanks,
ceTe Software Support Team.
 Apr 21 2016 4:46 PM
Thanks for the clarification! The issue was that I was attempting to do these operations while using a MergeDocument object rather than a PdfDocument object.

All times are US Eastern Standard time. The time now is 4:45 AM.