Class PdfFormField

Direct Known Subclasses:
PdfButtonFormField, PdfChoiceFormField, PdfSignatureFormField, PdfTextFormField

public class PdfFormField extends PdfObjectWrapper<PdfDictionary>
This class represents a single field or field group in an AcroForm.

To be able to be wrapped with this PdfObjectWrapper the PdfObject must be indirect.

  • Field Details

    • FF_MULTILINE

      public static final int FF_MULTILINE
      Flag that designates, if set, that the field can contain multiple lines of text.
    • FF_PASSWORD

      public static final int FF_PASSWORD
      Flag that designates, if set, that the field's contents must be obfuscated.
    • ALIGN_LEFT

      public static final int ALIGN_LEFT
      See Also:
    • ALIGN_CENTER

      public static final int ALIGN_CENTER
      See Also:
    • ALIGN_RIGHT

      public static final int ALIGN_RIGHT
      See Also:
    • TYPE_CHECK

      public static final int TYPE_CHECK
      A field with the symbol check
      See Also:
    • TYPE_CIRCLE

      public static final int TYPE_CIRCLE
      A field with the symbol circle
      See Also:
    • TYPE_CROSS

      public static final int TYPE_CROSS
      A field with the symbol cross
      See Also:
    • TYPE_DIAMOND

      public static final int TYPE_DIAMOND
      A field with the symbol diamond
      See Also:
    • TYPE_SQUARE

      public static final int TYPE_SQUARE
      A field with the symbol square
      See Also:
    • TYPE_STAR

      public static final int TYPE_STAR
      A field with the symbol star
      See Also:
    • HIDDEN

      public static final int HIDDEN
      See Also:
    • VISIBLE_BUT_DOES_NOT_PRINT

      public static final int VISIBLE_BUT_DOES_NOT_PRINT
      See Also:
    • HIDDEN_BUT_PRINTABLE

      public static final int HIDDEN_BUT_PRINTABLE
      See Also:
    • VISIBLE

      public static final int VISIBLE
      See Also:
    • FF_READ_ONLY

      public static final int FF_READ_ONLY
    • FF_REQUIRED

      public static final int FF_REQUIRED
    • FF_NO_EXPORT

      public static final int FF_NO_EXPORT
    • text

      protected String text
    • img

      protected ImageData img
    • font

      protected PdfFont font
    • fontSize

      protected float fontSize
    • color

      protected Color color
    • checkType

      protected int checkType
    • borderWidth

      protected float borderWidth
    • backgroundColor

      protected Color backgroundColor
    • borderColor

      protected Color borderColor
    • rotation

      protected int rotation
    • form

      protected PdfFormXObject form
    • pdfAConformanceLevel

      protected PdfAConformanceLevel pdfAConformanceLevel
  • Constructor Details

    • PdfFormField

      public PdfFormField (PdfDictionary pdfObject)
      Creates a form field as a wrapper object around a PdfDictionary. This PdfDictionary must be an indirect object.
      Parameters:
      pdfObject - the dictionary to be wrapped, must have an indirect reference.
    • PdfFormField

      protected PdfFormField (PdfDocument pdfDocument)
      Creates a minimal PdfFormField.
      Parameters:
      pdfDocument - The document
    • PdfFormField

      protected PdfFormField (PdfWidgetAnnotation widget, PdfDocument pdfDocument)
      Creates a form field as a parent of a PdfWidgetAnnotation.
      Parameters:
      widget - The widget which will be a kid of the PdfFormField
      pdfDocument - The document
  • Method Details

    • makeFieldFlag

      public static int makeFieldFlag (int bitPosition)
      Makes a field flag by bit position. Bit positions are numbered 1 to 32. But position 0 corresponds to flag 1, position 3 corresponds to flag 4 etc.
      Parameters:
      bitPosition - bit position of a flag in range 1 to 32 from the pdf specification.
      Returns:
      corresponding field flag.
    • createEmptyField

      public static PdfFormField createEmptyField (PdfDocument doc)
      Creates an empty form field without a predefined set of layout or behavior.
      Parameters:
      doc - the PdfDocument to create the field in
      Returns:
      a new PdfFormField
    • createEmptyField

      public static PdfFormField createEmptyField (PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty form field without a predefined set of layout or behavior.
      Parameters:
      doc - the PdfDocument to create the field in
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfFormField
    • createButton

      public static PdfButtonFormField createButton (PdfDocument doc, Rectangle rect, int flags)
      Creates an empty button form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the button field in
      rect - the location on the page for the button
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      Returns:
      a new PdfButtonFormField
    • createButton

      public static PdfButtonFormField createButton (PdfDocument doc, Rectangle rect, int flags, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty button form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the button field in
      rect - the location on the page for the button
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfButtonFormField
    • createButton

      public static PdfButtonFormField createButton (PdfDocument doc, int flags)
      Creates an empty button form field with custom behavior and layout.
      Parameters:
      doc - the PdfDocument to create the button field in
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      Returns:
      a new PdfButtonFormField
    • createButton

      public static PdfButtonFormField createButton (PdfDocument doc, int flags, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty button form field with custom behavior and layout.
      Parameters:
      doc - the PdfDocument to create the button field in
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfButtonFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc)
      Creates an empty text form field.
      Parameters:
      doc - the PdfDocument to create the text field in
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty text form field.
      Parameters:
      doc - the PdfDocument to create the text field in
      pdfAConformanceLevel - the desired PdfAConformanceLevel of the field. Must match the conformance level of the PdfDocument this field will eventually be added into
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, Rectangle rect)
      Creates an empty text form field.
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, Rectangle rect, String name)
      Creates a named text form field with an initial value, and the form's default font specified in PdfAcroForm.getDefaultResources().
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, Rectangle rect, String name, String value)
      Creates a named text form field with an initial value, and the form's default font specified in PdfAcroForm.getDefaultResources().
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      value - the initial value
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize)
      Creates a named text form field with an initial value, with a specified font and font size.
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      value - the initial value
      font - a PdfFont
      fontSize - the size of the font
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, boolean multiline)
      Creates a named text form field with an initial value, with a specified font and font size.
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      value - the initial value
      font - a PdfFont
      fontSize - the size of the font
      multiline - true for multiline text field
      Returns:
      a new PdfTextFormField
    • createText

      public static PdfTextFormField createText (PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, boolean multiline, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a named text form field with an initial value, with a specified font and font size.
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      value - the initial value
      font - a PdfFont
      fontSize - the size of the font
      multiline - true for multiline text field
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfTextFormField
    • createMultilineText

      public static PdfTextFormField createMultilineText (PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize)
      Creates a named multilined text form field with an initial value, with a specified font and font size.
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      value - the initial value
      font - a PdfFont
      fontSize - the size of the font
      Returns:
      a new PdfTextFormField
    • createMultilineText

      public static PdfTextFormField createMultilineText (PdfDocument doc, Rectangle rect, String name, String value)
      Creates a named multiline text form field with an initial value, and the form's default font specified in PdfAcroForm.getDefaultResources().
      Parameters:
      doc - the PdfDocument to create the text field in
      rect - the location on the page for the text field
      name - the name of the form field
      value - the initial value
      Returns:
      a new PdfTextFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, int flags)
      Creates an empty choice form field.
      Parameters:
      doc - the PdfDocument to create the choice field in
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      Returns:
      a new PdfChoiceFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, int flags, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty choice form field.
      Parameters:
      doc - the PdfDocument to create the choice field in
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, Rectangle rect, int flags)
      Creates an empty choice form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      Returns:
      a new PdfChoiceFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, Rectangle rect, String name, String value, PdfArray options, int flags)
      Creates a choice form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      name - the name of the form field
      value - the initial value
      options - an array of PdfString objects that each represent the 'on' state of one of the choices.
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      Returns:
      a new PdfChoiceFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, Rectangle rect, String name, String value, PdfArray options, int flags, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a choice form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      name - the name of the form field
      value - the initial value
      options - an array of PdfString objects that each represent the 'on' state of one of the choices.
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      font - the desired font to be used when displaying the text
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, PdfArray options, int flags)
      Creates a choice form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      name - the name of the form field
      value - the initial value
      font - a PdfFont
      fontSize - the size of the font
      options - an array of PdfString objects that each represent the 'on' state of one of the choices.
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      Returns:
      a new PdfChoiceFormField
    • createChoice

      public static PdfChoiceFormField createChoice (PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, PdfArray options, int flags, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a choice form field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      name - the name of the form field
      value - the initial value
      font - a PdfFont
      fontSize - the size of the font
      options - an array of PdfString objects that each represent the 'on' state of one of the choices.
      flags - an int, containing a set of binary behavioral flags. Do binary OR on this int to set the flags you require.
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField
    • createSignature

      public static PdfSignatureFormField createSignature (PdfDocument doc)
      Creates an empty signature form field.
      Parameters:
      doc - the PdfDocument to create the signature field in
      Returns:
      a new PdfSignatureFormField
    • createSignature

      public static PdfSignatureFormField createSignature (PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty signature form field.
      Parameters:
      doc - the PdfDocument to create the signature field in
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfSignatureFormField
    • createSignature

      public static PdfSignatureFormField createSignature (PdfDocument doc, Rectangle rect)
      Creates an empty signature form field.
      Parameters:
      doc - the PdfDocument to create the signature field in
      rect - the location on the page for the signature field
      Returns:
      a new PdfSignatureFormField
    • createSignature

      public static PdfSignatureFormField createSignature (PdfDocument doc, Rectangle rect, PdfAConformanceLevel pdfAConformanceLevel)
      Creates an empty signature form field.
      Parameters:
      doc - the PdfDocument to create the signature field in
      rect - the location on the page for the signature field
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfSignatureFormField
    • createRadioGroup

      public static PdfButtonFormField createRadioGroup (PdfDocument doc, String name, String value)
      Parameters:
      doc - the PdfDocument to create the radio group in
      name - the name of the form field
      value - the initial value
      Returns:
      a new radio group
    • createRadioGroup

      public static PdfButtonFormField createRadioGroup (PdfDocument doc, String name, String value, PdfAConformanceLevel pdfAConformanceLevel)
      Parameters:
      doc - the PdfDocument to create the radio group in
      name - the name of the form field
      value - the initial value
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new radio group
    • createRadioButton

      public static PdfFormField createRadioButton (PdfDocument doc, Rectangle rect, PdfButtonFormField radioGroup, String value)
      Creates a generic PdfFormField that is added to a radio group.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      radioGroup - the radio button group that this field should belong to
      value - the initial value
      Returns:
      a new PdfFormField
      See Also:
    • createRadioButton

      public static PdfFormField createRadioButton (PdfDocument doc, Rectangle rect, PdfButtonFormField radioGroup, String value, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a generic PdfFormField that is added to a radio group.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      radioGroup - the radio button group that this field should belong to
      value - the initial value
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfFormField
      See Also:
    • createPushButton

      public static PdfButtonFormField createPushButton (PdfDocument doc, Rectangle rect, String name, String caption)
      Creates a PdfButtonFormField as a push button without data.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      name - the name of the form field
      caption - the text to display on the button
      Returns:
      a new PdfButtonFormField
    • createPushButton

      public static PdfButtonFormField createPushButton (PdfDocument doc, Rectangle rect, String name, String caption, PdfFont font, float fontSize)
      Creates a PdfButtonFormField as a push button without data, with its caption in a custom font.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      name - the name of the form field
      caption - the text to display on the button
      font - a PdfFont
      fontSize - the size of the font
      Returns:
      a new PdfButtonFormField
    • createPushButton

      public static PdfButtonFormField createPushButton (PdfDocument doc, Rectangle rect, String name, String caption, PdfFont font, float fontSize, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a PdfButtonFormField as a push button without data, with its caption in a custom font.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      name - the name of the form field
      caption - the text to display on the button
      font - a PdfFont
      fontSize - the size of the font
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfButtonFormField
    • createCheckBox

      public static PdfButtonFormField createCheckBox (PdfDocument doc, Rectangle rect, String name, String value)
      Creates a PdfButtonFormField as a checkbox.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      name - the name of the form field
      value - the initial value
      Returns:
      a new checkbox
    • createCheckBox

      public static PdfButtonFormField createCheckBox (PdfDocument doc, Rectangle rect, String name, String value, int checkType)
      Creates a PdfButtonFormField as a checkbox.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      name - the name of the form field
      value - the initial value
      checkType - the type of checkbox graphic to use.
      Returns:
      a new checkbox
    • createCheckBox

      public static PdfButtonFormField createCheckBox (PdfDocument doc, Rectangle rect, String name, String value, int checkType, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a PdfButtonFormField as a checkbox. Check symbol will fit rectangle. You may set font and font size after creation.
      Parameters:
      doc - the PdfDocument to create the radio group in
      rect - the location on the page for the field
      name - the name of the form field
      value - the initial value
      checkType - the type of checkbox graphic to use.
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new checkbox
    • createComboBox

      public static PdfChoiceFormField createComboBox (PdfDocument doc, Rectangle rect, String name, String value, String[][] options)
      Creates a combobox with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the combobox in
      rect - the location on the page for the combobox
      name - the name of the form field
      value - the initial value
      options - a two-dimensional array of Strings which will be converted to a PdfArray.
      Returns:
      a new PdfChoiceFormField as a combobox
    • createComboBox

      public static PdfChoiceFormField createComboBox (PdfDocument doc, Rectangle rect, String name, String value, String[][] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a combobox with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the combobox in
      rect - the location on the page for the combobox
      name - the name of the form field
      value - the initial value
      options - a two-dimensional array of Strings which will be converted to a PdfArray.
      font - the desired font to be used when displaying the text
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField as a combobox
    • createComboBox

      public static PdfChoiceFormField createComboBox (PdfDocument doc, Rectangle rect, String name, String value, String[] options)
      Creates a combobox with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the combobox in
      rect - the location on the page for the combobox
      name - the name of the form field
      value - the initial value
      options - an array of Strings which will be converted to a PdfArray.
      Returns:
      a new PdfChoiceFormField as a combobox
    • createComboBox

      public static PdfChoiceFormField createComboBox (PdfDocument doc, Rectangle rect, String name, String value, String[] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a combobox with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the combobox in
      rect - the location on the page for the combobox
      name - the name of the form field
      value - the initial value
      options - an array of Strings which will be converted to a PdfArray.
      font - the desired font to be used when displaying the text
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField as a combobox
    • createList

      public static PdfChoiceFormField createList (PdfDocument doc, Rectangle rect, String name, String value, String[][] options)
      Creates a list field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      name - the name of the form field
      value - the initial value
      options - a two-dimensional array of Strings which will be converted to a PdfArray.
      Returns:
      a new PdfChoiceFormField as a list field
    • createList

      public static PdfChoiceFormField createList (PdfDocument doc, Rectangle rect, String name, String value, String[][] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a list field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the choice field in
      rect - the location on the page for the choice field
      name - the name of the form field
      value - the initial value
      options - a two-dimensional array of Strings which will be converted to a PdfArray.
      font - the desired font to be used when displaying the text
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField as a list field
    • createList

      public static PdfChoiceFormField createList (PdfDocument doc, Rectangle rect, String name, String value, String[] options)
      Creates a list field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the list field in
      rect - the location on the page for the list field
      name - the name of the form field
      value - the initial value
      options - an array of Strings which will be converted to a PdfArray.
      Returns:
      a new PdfChoiceFormField as a list field
    • createList

      public static PdfChoiceFormField createList (PdfDocument doc, Rectangle rect, String name, String value, String[] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel)
      Creates a list field with custom behavior and layout, on a specified location.
      Parameters:
      doc - the PdfDocument to create the list field in
      rect - the location on the page for the list field
      name - the name of the form field
      value - the initial value
      options - an array of Strings which will be converted to a PdfArray.
      font - the desired font to be used when displaying the text
      pdfAConformanceLevel - the PdfAConformanceLevel of the document. null if it's no PDF/A document
      Returns:
      a new PdfChoiceFormField as a list field
    • makeFormField

      public static PdfFormField makeFormField (PdfObject pdfObject, PdfDocument document)
      Creates a (subtype of) PdfFormField object. The type of the object depends on the FT entry in the pdfObject parameter.
      Parameters:
      pdfObject - assumed to be either a PdfDictionary, or a PdfIndirectReference to a PdfDictionary
      document - the PdfDocument to create the field in
      Returns:
      a new PdfFormField, or null if pdfObject does not contain a FT entry
    • getFormType

      public PdfName getFormType()
      Returns the type of the parent form field, or of the wrapped object.
      Returns:
      the form type, as a PdfName
    • setValue

      public PdfFormField setValue (String value)
      Sets a value to the field and generating field appearance if needed.
      Parameters:
      value - of the field
      Returns:
      the field
    • setValue

      public PdfFormField setValue (String value, boolean generateAppearance)
      Sets a value to the field and generates field appearance if needed.
      Parameters:
      value - of the field
      generateAppearance - if false, appearance won't be regenerated
      Returns:
      the field
    • setValue

      public PdfFormField setValue (String value, PdfFont font, float fontSize)
      Set text field value with given font and size
      Parameters:
      value - text value
      font - a PdfFont
      fontSize - the size of the font
      Returns:
      the edited field
    • setValue

      public PdfFormField setValue (String value, String display)
      Sets the field value and the display string. The display string is used to build the appearance.
      Parameters:
      value - the field value
      display - the string that is used for the appearance. If null the value parameter will be used
      Returns:
      the edited field
    • setParent

      public PdfFormField setParent (PdfFormField parent)
      Sets a parent PdfFormField for the current object.
      Parameters:
      parent - another form field that this field belongs to, usually a group field
      Returns:
      the edited field
    • getParent

      public PdfDictionary getParent()
      Gets the parent dictionary.
      Returns:
      another form field that this field belongs to, usually a group field
    • getKids

      public PdfArray getKids()
      Gets the kids of this object.
      Returns:
      contents of the dictionary's Kids property, as a PdfArray
    • addKid

      public PdfFormField addKid (PdfFormField kid)
      Adds a new kid to the Kids array property from a PdfFormField. Also sets the kid's Parent property to this object.
      Parameters:
      kid - a new PdfFormField entry for the field's Kids array property
      Returns:
      the edited field
    • addKid

      public PdfFormField addKid (PdfWidgetAnnotation kid)
      Adds a new kid to the Kids array property from a PdfWidgetAnnotation. Also sets the kid's Parent property to this object.
      Parameters:
      kid - a new PdfWidgetAnnotation entry for the field's Kids array property
      Returns:
      the edited field
    • setFieldName

      public PdfFormField setFieldName (String name)
      Changes the name of the field to the specified value.
      Parameters:
      name - the new field name, as a String
      Returns:
      the edited field
    • getFieldName

      public PdfString getFieldName()
      Gets the current field name.
      Returns:
      the current field name, as a PdfString
    • setAlternativeName

      public PdfFormField setAlternativeName (String name)
      Changes the alternate name of the field to the specified value. The alternate is a descriptive name to be used by status messages etc.
      Parameters:
      name - the new alternate name, as a String
      Returns:
      the edited field
    • getAlternativeName

      public PdfString getAlternativeName()
      Gets the current alternate name. The alternate is a descriptive name to be used by status messages etc.
      Returns:
      the current alternate name, as a PdfString
    • setMappingName

      public PdfFormField setMappingName (String name)
      Changes the mapping name of the field to the specified value. The mapping name can be used when exporting the form data in the document.
      Parameters:
      name - the new alternate name, as a String
      Returns:
      the edited field
    • getMappingName

      public PdfString getMappingName()
      Gets the current mapping name. The mapping name can be used when exporting the form data in the document.
      Returns:
      the current mapping name, as a PdfString
    • getFieldFlag

      public boolean getFieldFlag (int flag)
      Checks whether a certain flag, or any of a combination of flags, is set for this form field.
      Parameters:
      flag - an int interpreted as a series of a binary flags
      Returns:
      true if any of the flags specified in the parameter is also set in the form field.
    • setFieldFlag

      public PdfFormField setFieldFlag (int flag)
      Adds a flag, or combination of flags, for the form field. This method is intended to be used one flag at a time, but this is not technically enforced. To replace the current value, use setFieldFlags(int).
      Parameters:
      flag - an int interpreted as a series of a binary flags
      Returns:
      the edited field
    • setFieldFlag

      public PdfFormField setFieldFlag (int flag, boolean value)
      Adds or removes a flag, or combination of flags, for the form field. This method is intended to be used one flag at a time, but this is not technically enforced. To replace the current value, use setFieldFlags(int).
      Parameters:
      flag - an int interpreted as a series of a binary flags
      value - if true, adds the flag(s). if false, removes the flag(s).
      Returns:
      the edited field
    • isMultiline

      public boolean isMultiline()
      If true, the field can contain multiple lines of text; if false, the field's text is restricted to a single line.
      Returns:
      whether the field can span over multiple lines.
    • isPassword

      public boolean isPassword()
      If true, the field is intended for entering a secure password that should not be echoed visibly to the screen. Characters typed from the keyboard should instead be echoed in some unreadable form, such as asterisks or bullet characters.
      Returns:
      whether or not the contents of the field must be obfuscated
    • setFieldFlags

      public PdfFormField setFieldFlags (int flags)
      Sets a flag, or combination of flags, for the form field. This method replaces the previous value. Compare with setFieldFlag(int) which adds a flag to the existing flags.
      Parameters:
      flags - an int interpreted as a series of a binary flags
      Returns:
      the edited field
    • getFieldFlags

      public int getFieldFlags()
      Gets the current list of PDF form field flags.
      Returns:
      the current list of flags, encoded as an int
    • getValue

      public PdfObject getValue()
      Gets the current value contained in the form field.
      Returns:
      the current value, as a PdfObject
    • getValueAsString

      public String getValueAsString()
      Gets the current value contained in the form field.
      Returns:
      the current value, as a String
    • setDefaultValue

      public PdfFormField setDefaultValue (PdfObject value)
      Sets the default fallback value for the form field.
      Parameters:
      value - the default value
      Returns:
      the edited field
    • getDefaultValue

      public PdfObject getDefaultValue()
      Gets the default fallback value for the form field.
      Returns:
      the default value
    • setAdditionalAction

      public PdfFormField setAdditionalAction (PdfName key, PdfAction action)
      Sets an additional action for the form field.
      Parameters:
      key - the dictionary key to use for storing the action
      action - the action
      Returns:
      the edited field
    • getAdditionalAction

      public PdfDictionary getAdditionalAction()
      Gets the currently additional action dictionary for the form field.
      Returns:
      the additional action dictionary
    • setOptions

      public PdfFormField setOptions (PdfArray options)
      Sets options for the form field. Only to be used for checkboxes and radio buttons.
      Parameters:
      options - an array of PdfString objects that each represent the 'on' state of one of the choices.
      Returns:
      the edited field
    • getOptions

      public PdfArray getOptions()
      Gets options for the form field. Should only return usable values for checkboxes and radio buttons.
      Returns:
      the options, as an PdfArray of PdfString objects
    • getWidgets

      public List<PdfWidgetAnnotation> getWidgets()
      Gets all PdfWidgetAnnotation that this form field and its kids refer to.
      Returns:
      a list of PdfWidgetAnnotation
    • getDefaultAppearance

      public PdfString getDefaultAppearance()
      Gets default appearance string containing a sequence of valid page-content graphics or text state operators that define such properties as the field's text size and color.
      Returns:
      the default appearance graphics, as a PdfString
    • updateDefaultAppearance

      public void updateDefaultAppearance()
      Updates DA for Variable text, Push button and choice form fields. The resources required for DA will be put to AcroForm's DR. Note, for other form field types DA will be removed.
    • getJustification

      public Integer getJustification()
      Gets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justified
      Returns:
      the current justification attribute
    • setJustification

      public PdfFormField setJustification (int justification)
      Sets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justified
      Parameters:
      justification - the value to set the justification attribute to
      Returns:
      the edited field
    • getDefaultStyle

      public PdfString getDefaultStyle()
      Gets a default style string, as described in "Rich Text Strings" section of Pdf spec.
      Returns:
      the default style, as a PdfString
    • setDefaultStyle

      public PdfFormField setDefaultStyle (PdfString defaultStyleString)
      Sets a default style string, as described in "Rich Text Strings" section of Pdf spec.
      Parameters:
      defaultStyleString - a new default style for the form field
      Returns:
      the edited field
    • getRichText

      public PdfObject getRichText()
      Gets a rich text string, as described in "Rich Text Strings" section of Pdf spec. May be either PdfStream or PdfString.
      Returns:
      the current rich text value
    • setRichText

      public PdfFormField setRichText (PdfObject richText)
      Sets a rich text string, as described in "Rich Text Strings" section of Pdf spec. May be either PdfStream or PdfString.
      Parameters:
      richText - a new rich text value
      Returns:
      The edited PdfFormField
    • getFontSize

      public float getFontSize()
      Gets the current fontSize of the form field.
      Returns:
      the current fontSize
    • getFont

      public PdfFont getFont()
      Gets the current font of the form field.
      Returns:
      the current font
    • getColor

      public Color getColor()
      Gets the current color of the form field.
      Returns:
      the current color
    • setFont

      public PdfFormField setFont (PdfFont font)
      Basic setter for the font property. Regenerates the field appearance after setting the new value. Note that the font will be added to the document so ensure that the font is embedded if it's a pdf/a document.
      Parameters:
      font - The new font to be set
      Returns:
      The edited PdfFormField
    • setFontSize

      public PdfFormField setFontSize (float fontSize)
      Basic setter for the fontSize property. Regenerates the field appearance after setting the new value.
      Parameters:
      fontSize - The new font size to be set
      Returns:
      The edited PdfFormField
    • setFontSize

      public PdfFormField setFontSize (int fontSize)
      Basic setter for the fontSize property. Regenerates the field appearance after setting the new value.
      Parameters:
      fontSize - The new font size to be set
      Returns:
      The edited PdfFormField
    • setFontAndSize

      public PdfFormField setFontAndSize (PdfFont font, float fontSize)
      Combined setter for the font and fontSize properties. Regenerates the field appearance after setting the new value.
      Parameters:
      font - The new font to be set
      fontSize - The new font size to be set
      Returns:
      The edited PdfFormField
    • setBackgroundColor

      public PdfFormField setBackgroundColor (Color backgroundColor)
      Basic setter for the backgroundColor property. Regenerates the field appearance after setting the new value.
      Parameters:
      backgroundColor - The new color to be set or null if no background needed
      Returns:
      The edited PdfFormField
    • setRotation

      public PdfFormField setRotation (int degRotation)
      Basic setter for the degRotation property. Regenerates the field appearance after setting the new value.
      Parameters:
      degRotation - The new degRotation to be set
      Returns:
      The edited PdfFormField
    • setAction

      public PdfFormField setAction (PdfAction action)
      Sets the action on all widgets of this form field.
      Parameters:
      action - The action
      Returns:
      The edited field
    • setCheckType

      public PdfFormField setCheckType (int checkType)
      Changes the type of graphical marker used to mark a checkbox as 'on'. Notice that in order to complete the change one should call regenerateField method
      Parameters:
      checkType - the new checkbox marker
      Returns:
      The edited field
    • setVisibility

      public PdfFormField setVisibility (int visibility)
      Set the visibility flags of the form field annotation Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT
      Parameters:
      visibility - visibility option
      Returns:
      The edited field
    • regenerateField

      public boolean regenerateField()
      This method regenerates appearance stream of the field. Use it if you changed any field parameters and didn't use setValue method which generates appearance by itself.
      Returns:
      whether or not the regeneration was successful.
    • getBorderWidth

      public float getBorderWidth()
      Gets the border width for the field.
      Returns:
      the current border width.
    • setBorderWidth

      public PdfFormField setBorderWidth (float borderWidth)
      Sets the border width for the field.
      Parameters:
      borderWidth - The new border width.
      Returns:
      The edited field
    • setBorderStyle

      public PdfFormField setBorderStyle (PdfDictionary style)
      Sets the border style for the field.
      Parameters:
      style - the new border style.
      Returns:
      the edited field
    • setBorderColor

      public PdfFormField setBorderColor (Color color)
      Sets the Border Color.
      Parameters:
      color - the new value for the Border Color
      Returns:
      the edited field
    • setColor

      public PdfFormField setColor (Color color)
      Sets the text color.
      Parameters:
      color - the new value for the Color
      Returns:
      the edited field
    • setReadOnly

      public PdfFormField setReadOnly (boolean readOnly)
      Sets the ReadOnly flag, specifying whether or not the field can be changed.
      Parameters:
      readOnly - if true, then the field cannot be changed.
      Returns:
      the edited field
    • isReadOnly

      public boolean isReadOnly()
      Gets the ReadOnly flag, specifying whether or not the field can be changed.
      Returns:
      true if the field cannot be changed.
    • setRequired

      public PdfFormField setRequired (boolean required)
      Sets the Required flag, specifying whether or not the field must be filled in.
      Parameters:
      required - if true, then the field must be filled in.
      Returns:
      the edited field
    • isRequired

      public boolean isRequired()
      Gets the Required flag, specifying whether or not the field must be filled in.
      Returns:
      true if the field must be filled in.
    • setNoExport

      public PdfFormField setNoExport (boolean noExport)
      Sets the NoExport flag, specifying whether or not exporting is forbidden.
      Parameters:
      noExport - if true, then exporting is forbidden
      Returns:
      the edited field
    • isNoExport

      public boolean isNoExport()
      Gets the NoExport attribute.
      Returns:
      whether exporting the value following a form action is forbidden.
    • setPage

      public PdfFormField setPage (int pageNum)
      Specifies on which page the form field's widget must be shown.
      Parameters:
      pageNum - the page number
      Returns:
      the edited field
    • getAppearanceStates

      public String[] getAppearanceStates()
      Gets the appearance state names.
      Returns:
      an array of Strings containing the names of the appearance states
    • setAppearance

      public PdfFormField setAppearance (PdfName appearanceType, String appearanceState, PdfStream appearanceStream)
      Sets an appearance for (the widgets related to) the form field.
      Parameters:
      appearanceType - the type of appearance stream to be added
      • PdfName.N: normal appearance
      • PdfName.R: rollover appearance
      • PdfName.D: down appearance
      appearanceState - the state of the form field that needs to be true for the appearance to be used. Differentiates between several streams of the same type.
      appearanceStream - the appearance instructions, as a PdfStream
      Returns:
      the edited field
    • setFontSizeAutoScale

      public PdfFormField setFontSizeAutoScale()
      Sets zero font size which will be interpreted as auto-size according to ISO 32000-1, 12.7.3.3.
      Returns:
      the edited field
    • put

      public PdfFormField put (PdfName key, PdfObject value)
      Inserts the value into the PdfDictionary of this field and associates it with the specified key. If the key is already present in this field dictionary, this method will override the old value with the specified one.
      Parameters:
      key - key to insert or to override
      value - the value to associate with the specified key
      Returns:
      this PdfFormField instance
    • remove

      public PdfFormField remove (PdfName key)
      Removes the specified key from the PdfDictionary of this field.
      Parameters:
      key - key to be removed
      Returns:
      this PdfFormField instance
    • release

      public void release()
      Releases underlying pdf object and other pdf entities used by wrapper. This method should be called instead of direct call to PdfObject.release() if the wrapper is used.
    • isWrappedObjectMustBeIndirect

      protected boolean isWrappedObjectMustBeIndirect()
      Description copied from class: PdfObjectWrapper
      Defines if the object behind this wrapper must be an indirect object in the resultant document.

      If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.

      Return value of this method shouldn't depend on any logic, it should return always true or false.
      Specified by:
      isWrappedObjectMustBeIndirect in class PdfObjectWrapper<PdfDictionary>
      Returns:
      true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
    • getDocument

      protected PdfDocument getDocument()
      Gets the PdfDocument that owns that form field.
      Returns:
      the PdfDocument that owns that form field.
    • getRect

      protected Rectangle getRect (PdfDictionary field)
      Gets a Rectangle that matches the current size and position of this form field.
      Parameters:
      field - current form field.
      Returns:
      a Rectangle that matches the current size and position of this form field.
    • processOptions

      protected static PdfArray processOptions (String[][] options)
      Convert String multidimensional array of combo box or list options to PdfArray.
      Parameters:
      options - Two-dimensional array of options.
      Returns:
      a PdfArray that contains all the options.
    • processOptions

      protected static PdfArray processOptions (String[] options)
      Convert String array of combo box or list options to PdfArray.
      Parameters:
      options - array of options.
      Returns:
      a PdfArray that contains all the options.
    • splitDAelements

      protected static Object[] splitDAelements (String da)
    • drawTextAppearance

      protected void drawTextAppearance (Rectangle rect, PdfFont font, float fontSize, String value, PdfFormXObject appearance)
      Draws the visual appearance of text in a form field.
      Parameters:
      rect - The location on the page for the list field
      font - a PdfFont
      fontSize - The size of the font
      value - The initial value
      appearance - The appearance
    • drawMultiLineTextAppearance

      protected void drawMultiLineTextAppearance (Rectangle rect, PdfFont font, String value, PdfFormXObject appearance)
    • drawBorder

      protected void drawBorder (PdfCanvas canvas, PdfFormXObject xObject, float width, float height)
      Draws a border using the borderWidth and borderColor of the form field.
      Parameters:
      canvas - The PdfCanvas on which to draw
      xObject - The PdfFormXObject
      width - The width of the rectangle to draw
      height - The height of the rectangle to draw
    • drawRadioBorder

      protected void drawRadioBorder (PdfCanvas canvas, PdfFormXObject xObject, float width, float height)
    • drawRadioAppearance

      protected void drawRadioAppearance (float width, float height, String value)
      Draws the appearance of a radio button with a specified value.
      Parameters:
      width - the width of the radio button to draw
      height - the height of the radio button to draw
      value - the value of the button
    • drawRadioField

      protected void drawRadioField (PdfCanvas canvas, float width, float height, boolean on)
      Draws a radio button.
      Parameters:
      canvas - the PdfCanvas on which to draw
      width - the width of the radio button to draw
      height - the height of the radio button to draw
      on - required to be true for fulfilling the drawing operation
    • drawCheckAppearance

      protected void drawCheckAppearance (float width, float height, String onStateName)
      Draws the appearance of a checkbox with a specified state value.
      Parameters:
      width - the width of the checkbox to draw
      height - the height of the checkbox to draw
      onStateName - the state of the form field that will be drawn
    • drawPdfA2CheckAppearance

      protected void drawPdfA2CheckAppearance (float width, float height, String onStateName, int checkType)
      Draws PDF/A-2 compliant check appearance. Actually it's just PdfA check appearance. According to corrigendum there is no difference between them
      Parameters:
      width - width of the checkbox
      height - height of the checkbox
      onStateName - name that corresponds to the "On" state of the checkbox
      checkType - the type that determines how the checkbox will look like. Allowed values are TYPE_CHECK, TYPE_CIRCLE, TYPE_CROSS, TYPE_DIAMOND, TYPE_SQUARE, TYPE_STAR
    • drawPushButtonAppearance

      protected PdfFormXObject drawPushButtonAppearance (float width, float height, String text, PdfFont font, float fontSize)
      Draws the appearance for a push button.
      Parameters:
      width - the width of the pushbutton
      height - the width of the pushbutton
      text - the text to display on the button
      font - a PdfFont
      fontSize - the size of the font
      Returns:
      a new PdfFormXObject
    • drawButton

      protected void drawButton (PdfCanvas canvas, float x, float y, float width, float height, String text, PdfFont font, float fontSize)
      Performs the low-level drawing operations to draw a button object.
      Parameters:
      canvas - the PdfCanvas of the page to draw on.
      x - will be ignored, according to spec it shall be 0
      y - will be ignored, according to spec it shall be 0
      width - the width of the button
      height - the width of the button
      text - the text to display on the button
      font - a PdfFont
      fontSize - the size of the font
    • drawCheckBox

      protected void drawCheckBox (PdfCanvas canvas, float width, float height, float fontSize)
      Performs the low-level drawing operations to draw a checkbox object.
      Parameters:
      canvas - the PdfCanvas of the page to draw on.
      width - the width of the button
      height - the width of the button
      fontSize - the size of the font
    • drawPdfACheckBox

      protected void drawPdfACheckBox (PdfCanvas canvas, float width, float height, boolean on)