I’m using iText 2.1.7, included through the following dependency …
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
How do I change the text size of a PDF field in a PDF I’m trying to export? I created a PDF template using OpenOffice 4.1.0 and then have tried this code to set the text size:
final PdfReader pdfTemplate = new PdfReader(pdfTemplateFile.toString());
// Prepare to generate a byte output stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(pdfTemplate, out);
stamper.setFormFlattening(true);
…
stamper.getAcroFields().setField(PARTICIPANT_FIELD_NAME, user.getFirstName() + " " + user.getLastName());
stamper.getAcroFields().setFieldProperty(PARTICIPANT_FIELD_NAME, "textsize", new Float(36), null);
final BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
stamper.getAcroFields().setFieldProperty(PARTICIPANT_FIELD_NAME, "textfont", font, null);
No matter what value I put in between “new Float(xxx)”, the font size is always rendered the same. Where am I going wrong?