How to align AcroFields?

I'm using iText to populate the data to PDF templates, which are created in OpenOffice. The form is populating fine; I'm getting proper PDF, but I want to change the alignment of some fields. I am using the following code.

 

fields.setFieldProperty(fieldName, "fflags", PdfFormField.Q_LEFT, null);
Posted on StackOverflow on Jun 19, 2014 by Rajesh

The quadding isn't part of the field flags as you wrongly assumed. It's and entry of the widget annotation dictionary. This is how you change it:

AcroFields form = stamper.getAcroFields();
AcroFields.Item item;
item = form.getFieldItem("fieldLeft");
item.getMerged(0).put(PdfName.Q, new PdfNumber(PdfFormField.Q_LEFT));
item = form.getFieldItem("fieldCenter");
item.getMerged(0).put(PdfName.Q, new PdfNumber(PdfFormField.Q_CENTER));
item = form.getFieldItem("fieldRight");
item.getMerged(0).put(PdfName.Q, new PdfNumber(PdfFormField.Q_RIGHT));

See the AlignField method for the full example.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now