How to align AcroFields?
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 How to align AcroFields? if you want to see how to answer this question in iText 5.