Skip to main content
Skip table of contents

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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.