Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Last active January 13, 2018 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpeterdelacruz/f76795db2e2a84fd566995ccee8f6d73 to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/f76795db2e2a84fd566995ccee8f6d73 to your computer and use it in GitHub Desktop.
How to set font size of field using iText 5
protected void setFirstNameField(AcroFields form) throws IOException, DocumentException {
// Set font size.
form.setFieldProperty("first_name", "textsize", 10f, null);
// Set font to use.
final BaseFont font = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED);
form.setFieldProperty("first_name", "textfont", font, null);
// The font size must be set first before setting the value of the field.
form.setField("first_name", value);
form.setFieldProperty("first_name", "setfflags", PdfFormField.FF_READ_ONLY, null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment