Package com.ironsoftware.ironpdf.form
Class FormManager
- java.lang.Object
-
- com.ironsoftware.ironpdf.form.FormManager
-
public class FormManager extends Object
Class used to read and write data to AcroForms in aPdfDocument.
-
-
Constructor Summary
Constructors Constructor Description FormManager(com.ironsoftware.ironpdf.internal.staticapi.InternalPdfDocument internalPdfDocument)Please get FormManager byPdfDocument.getForm()instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voiddisableFormFontFallback()Suppresses the automatic Tahoma/Arial fallback embed for non-ASCII form values without registering any replacement font.voidflatten()Flattens a document (make all form fields non-editable).voidflatten(PageSelection pageSelection)Flattens a document (make all form fields non-editable).FormFieldsSetgetFields()Get a collection of the user-editable form fields within a PDF documentStringrenameField(String currentFieldName, String newFieldName)Rename aFormFieldvoidsetFieldReadOnly(String fieldName, boolean value)Set the is read only value of aFormFieldvoidsetFieldValue(String fieldName, String value)Set the string value of aFormFieldvoidsetFormFont(String fontName)Sets the document-wide form font by name only.voidsetFormFont(String fontName, byte[] fontData)Sets the document-wide form font without forcing a re-embed.voidsetFormFont(String fontName, byte[] fontData, boolean forceEmbed)Sets the document-wide font for all subsequent form-field fills on this document.voidsetFormFontFromFile(Path fontFilePath)Loads a TrueType/OpenType font from disk and applies it as the document-wide form font.voidsetFormFontFromFile(Path fontFilePath, String fontName, boolean forceEmbed)Loads a TrueType/OpenType font from disk and applies it as the document-wide form font.voidsetTextFieldFont(String textFieldName, FontTypes font, int fontSize)Deprecated.This method is deprecated and no longer has any effect.
-
-
-
Constructor Detail
-
FormManager
public FormManager(com.ironsoftware.ironpdf.internal.staticapi.InternalPdfDocument internalPdfDocument)
Please get FormManager byPdfDocument.getForm()instead.- Parameters:
internalPdfDocument- the internal pdf document
-
-
Method Detail
-
flatten
public final void flatten()
Flattens a document (make all form fields non-editable).
-
flatten
public final void flatten(PageSelection pageSelection)
Flattens a document (make all form fields non-editable).- Parameters:
pageSelection- Selected page indexes. Default is all pages.
-
getFields
public FormFieldsSet getFields()
Get a collection of the user-editable form fields within a PDF document- Returns:
- FormFieldsSet
-
renameField
public String renameField(String currentFieldName, String newFieldName)
Rename aFormField- Parameters:
currentFieldName- Current fully qualified field namenewFieldName- New partial field name Please use a fully qualified field name for CurrentFieldName, and a partial field name for NewFieldName- Returns:
- New fully-qualified field name
-
setFieldValue
public void setFieldValue(String fieldName, String value)
Set the string value of aFormField- Parameters:
fieldName- Fully qualified field namevalue- New value
-
setFieldReadOnly
public void setFieldReadOnly(String fieldName, boolean value)
Set the is read only value of aFormField- Parameters:
fieldName- Fully qualified field namevalue- is read only
-
setTextFieldFont
public void setTextFieldFont(String textFieldName, FontTypes font, int fontSize)
Deprecated.This method is deprecated and no longer has any effect. Set the font of aTextField- Parameters:
textFieldName- Fully qualified field namefont- New fontfontSize- New font size
-
setFormFont
public void setFormFont(String fontName, byte[] fontData, boolean forceEmbed)
Sets the document-wide font for all subsequent form-field fills on this document.The engine only auto-embeds the Tahoma/Arial fallback when a form value containing non-ASCII characters is set. Every other field update (renaming, toggling read-only, etc.) leaves fonts untouched, so this method is only useful when at least one of your fills contains non-ASCII characters.
If your form fields reference more than one font variant (e.g. Poppins-Regular and Poppins-Bold), call this method once per variant.
File-size impact
- Name-only mode (
fontDatais null/empty): zero bytes added; the font must already be in the document. - Bytes mode and the font is already embedded with usable glyph data: zero bytes added.
- Bytes mode and the font is missing or has no glyph data: the full font is embedded.
- Bytes mode with
forceEmbed = true: a fresh font copy is added alongside any existing copy; the document grows by the size of the new font on every call. Use sparingly.
- Parameters:
fontName- PDF font name to register (e.g. "Poppins-Regular"). Allowed characters: letters, digits, '-', '_', '.', '+'.fontData- Raw TrueType/OpenType bytes; pass null or empty for name-only mode (the font must already be in the document).forceEmbed- When true, embedfontDataeven if a font with the same name and usable glyph data is already present. Has no effect in name-only mode.- Throws:
IllegalArgumentException- whenfontNameorfontDatafails validation
- Name-only mode (
-
setFormFont
public void setFormFont(String fontName, byte[] fontData)
Sets the document-wide form font without forcing a re-embed. Equivalent tosetFormFont(fontName, fontData, false).- Parameters:
fontName- PDF font name to registerfontData- Raw font bytes, or null/empty for name-only mode- Throws:
IllegalArgumentException- whenfontNameorfontDatafails validation
-
setFormFont
public void setFormFont(String fontName)
Sets the document-wide form font by name only. The font must already be in the document (e.g. embedded by the template, or added via a previous call with bytes).- Parameters:
fontName- PDF font name as it appears in the document- Throws:
IllegalArgumentException- whenfontNamefails validation
-
setFormFontFromFile
public void setFormFontFromFile(Path fontFilePath) throws IOException
Loads a TrueType/OpenType font from disk and applies it as the document-wide form font. The PDF font name is derived from the file name (without extension).- Parameters:
fontFilePath- Path to a TTF/OTF/TTC font file- Throws:
IOException- when the font file cannot be readIllegalArgumentException- when the file or derived font name fails validation
-
setFormFontFromFile
public void setFormFontFromFile(Path fontFilePath, String fontName, boolean forceEmbed) throws IOException
Loads a TrueType/OpenType font from disk and applies it as the document-wide form font.- Parameters:
fontFilePath- Path to a TTF/OTF/TTC font filefontName- Optional PDF font name to register the font under. When null, the file name without extension is used.forceEmbed- When true, embed even if the font is already present.- Throws:
IOException- when the font file cannot be readIllegalArgumentException- when the file or derived font name fails validation
-
disableFormFontFallback
public void disableFormFontFallback()
Suppresses the automatic Tahoma/Arial fallback embed for non-ASCII form values without registering any replacement font. Use when zero file-size growth is required and the template's existing font references are sufficient for the values being filled.Rendering of non-ASCII characters then depends entirely on the viewer's font substitution — best for ASCII or Latin-Extended fills where the template already references suitable fonts. For broader character ranges, use
setFormFont(String, byte[], boolean)instead.
-
-