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.

31st May 2016
admin-marketing

I am using the following code.

 

fields.setFieldProperty(fieldName, "fflags", PdfFormField.Q_LEFT, null);

 

Posted on StackOverflow on Jun 19, 2014 by Rajesh

In iText 7 to set the correct alignment of text you should use setJustification() method:

PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
Map fields = form.getFormFields();
PdfFormField field;
field = fields.get("personal.name");
field.setJustification(PdfFormField.ALIGN_LEFT);
field.setValue("Test");
field = fields.get("personal.loginname");
field.setJustification(PdfFormField.ALIGN_CENTER);
field.setValue("Test");
field = fields.get("personal.password");
field.setJustification(PdfFormField.ALIGN_RIGHT);
field.setValue("Test");
field = fields.get("personal.reason");
field.setValue("Test");
pdfDoc.close();

See the AlignField for the full example.

Click this link if you want to see how to answer this question in iText 5.



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