Class BaseField

java.lang.Object
com.lowagie.text.pdf.BaseField
Direct Known Subclasses:
PushbuttonField, RadioCheckField, TextField

public abstract class BaseField extends Object
Common field variables.
  • Field Details

    • BORDER_WIDTH_THIN

      public static final float BORDER_WIDTH_THIN
      A thin border with 1 point width.
      See Also:
    • BORDER_WIDTH_MEDIUM

      public static final float BORDER_WIDTH_MEDIUM
      A medium border with 2 point width.
      See Also:
    • BORDER_WIDTH_THICK

      public static final float BORDER_WIDTH_THICK
      A thick border with 3 point width.
      See Also:
    • VISIBLE

      public static final int VISIBLE
      The field is visible.
      See Also:
    • HIDDEN

      public static final int HIDDEN
      The field is hidden.
      See Also:
    • VISIBLE_BUT_DOES_NOT_PRINT

      public static final int VISIBLE_BUT_DOES_NOT_PRINT
      The field is visible but does not print.
      See Also:
    • HIDDEN_BUT_PRINTABLE

      public static final int HIDDEN_BUT_PRINTABLE
      The field is hidden but is printable.
      See Also:
    • INVISIBLE

      public static final int INVISIBLE
      The annotation flag: Invisible.
      See Also:
    • PRINT

      public static final int PRINT
      The annotation flag Hidden.
      See Also:
    • NOVIEW

      public static final int NOVIEW
      The annotation flag Hidden.
      See Also:
    • LOCKED

      public static final int LOCKED
      The annotation flag Hidden.
      See Also:
    • READ_ONLY

      public static final int READ_ONLY
      The user may not change the value of the field.
      See Also:
    • REQUIRED

      public static final int REQUIRED
      The field must have a value at the time it is exported by a submit-form action.
      See Also:
    • MULTILINE

      public static final int MULTILINE
      The field may contain multiple lines of text. This flag is only meaningful with text fields.
      See Also:
    • DO_NOT_SCROLL

      public static final int DO_NOT_SCROLL
      The field will not scroll (horizontally for single-line fields, vertically for multiple-line fields) to accommodate more text than will fit within its annotation rectangle. Once the field is full, no further text will be accepted.
      See Also:
    • PASSWORD

      public static final int PASSWORD
      The field is intended for entering a secure password that should not be echoed visibly to the screen.
      See Also:
    • FILE_SELECTION

      public static final int FILE_SELECTION
      The text entered in the field represents the pathname of a file whose contents are to be submitted as the value of the field.
      See Also:
    • DO_NOT_SPELL_CHECK

      public static final int DO_NOT_SPELL_CHECK
      The text entered in the field will not be spell-checked. This flag is meaningful only in text fields and in combo fields with the EDIT flag set.
      See Also:
    • EDIT

      public static final int EDIT
      If set the combo box includes an editable text box as well as a drop list; if clear, it includes only a drop list. This flag is only meaningful with combo fields.
      See Also:
    • MULTISELECT

      public static final int MULTISELECT
      whether or not a list may have multiple selections. Only applies to /CH LIST fields, not combo boxes.
      See Also:
    • COMB

      public static final int COMB
      combo box flag.
      See Also:
    • fieldKeys

      private static final Map<PdfName,Integer> fieldKeys
    • borderWidth

      protected float borderWidth
    • borderStyle

      protected int borderStyle
    • borderColor

      protected Color borderColor
    • backgroundColor

      protected Color backgroundColor
    • textColor

      protected Color textColor
    • font

      protected BaseFont font
    • fontSize

      protected float fontSize
    • alignment

      protected int alignment
    • writer

      protected PdfWriter writer
    • text

      protected String text
    • box

      protected Rectangle box
    • rotation

      protected int rotation
      Holds value of property rotation.
    • visibility

      protected int visibility
      Holds value of property visibility.
    • fieldName

      protected String fieldName
      Holds value of property fieldName.
    • alternateFieldName

      protected String alternateFieldName
      Holds the value of the alternate field name. (PDF attribute 'TU')
    • mappingName

      protected String mappingName
      Holds the value of the mapping field name. (PDF attribute 'TM')
    • options

      protected int options
      Holds value of property options.
    • maxCharacterLength

      protected int maxCharacterLength
      Holds value of property maxCharacterLength.
  • Constructor Details

    • BaseField

      public BaseField(PdfWriter writer, Rectangle box, String fieldName)
      Creates a new TextField.
      Parameters:
      writer - the document PdfWriter
      box - the field location and dimensions
      fieldName - the field name. If null only the widget keys will be included in the field allowing it to be used as a kid field.
  • Method Details

    • getBorderAppearance

      protected static PdfAppearance getBorderAppearance(PdfWriter writer, Rectangle box, int rotation, Color backgroundColor, int borderStyle, float borderWidth, Color borderColor, int options, int maxCharacterLength)
    • getAllHardBreaks

      protected static List<String> getAllHardBreaks(String text)
    • trimRight

      protected static void trimRight(StringBuffer buf)
    • breakLines

      protected static List<String> breakLines(List<String> breaks, BaseFont font, float fontSize, float width)
    • drawTopFrame

      private static void drawTopFrame(PdfAppearance app, float borderWidth, Rectangle box)
    • drawBottomFrame

      private static void drawBottomFrame(PdfAppearance app, float borderWidth, Rectangle box)
    • moveFields

      public static void moveFields(PdfDictionary from, PdfDictionary to)
      Moves the field keys from from to to. The moved keys are removed from from.
      Parameters:
      from - the source
      to - the destination. It may be null
    • getRealFont

      protected BaseFont getRealFont() throws IOException, DocumentException
      Throws:
      IOException
      DocumentException
    • getBorderWidth

      public float getBorderWidth()
      Gets the border width in points.
      Returns:
      the border width in points
    • setBorderWidth

      public void setBorderWidth(float borderWidth)
      Sets the border width in points. To eliminate the border set the border color to null.
      Parameters:
      borderWidth - the border width in points
    • getBorderStyle

      public int getBorderStyle()
      Gets the border style.
      Returns:
      the border style
    • setBorderStyle

      public void setBorderStyle(int borderStyle)
      Sets the border style. The styles are found in PdfBorderDictionary and can be STYLE_SOLID, STYLE_DASHED, STYLE_BEVELED, STYLE_INSET and STYLE_UNDERLINE.
      Parameters:
      borderStyle - the border style
    • getBorderColor

      public Color getBorderColor()
      Gets the border color.
      Returns:
      the border color
    • setBorderColor

      public void setBorderColor(Color borderColor)
      Sets the border color. Set to null to remove the border.
      Parameters:
      borderColor - the border color
    • getBackgroundColor

      public Color getBackgroundColor()
      Gets the background color.
      Returns:
      the background color
    • setBackgroundColor

      public void setBackgroundColor(Color backgroundColor)
      Sets the background color. Set to null for transparent background.
      Parameters:
      backgroundColor - the background color
    • getTextColor

      public Color getTextColor()
      Gets the text color.
      Returns:
      the text color
    • setTextColor

      public void setTextColor(Color textColor)
      Sets the text color. If null the color used will be black.
      Parameters:
      textColor - the text color
    • getFont

      public BaseFont getFont()
      Gets the text font.
      Returns:
      the text font
    • setFont

      public void setFont(BaseFont font)
      Sets the text font. If null then Helvetica will be used.
      Parameters:
      font - the text font
    • getFontSize

      public float getFontSize()
      Gets the font size.
      Returns:
      the font size
    • setFontSize

      public void setFontSize(float fontSize)
      Sets the font size. If 0 then auto-sizing will be used but only for text fields.
      Parameters:
      fontSize - the font size
    • getAlignment

      public int getAlignment()
      Gets the text horizontal alignment.
      Returns:
      the text horizontal alignment
    • setAlignment

      public void setAlignment(int alignment)
      Sets the text horizontal alignment. It can be Element.ALIGN_LEFT, Element.ALIGN_CENTER and Element.ALIGN_RIGHT.
      Parameters:
      alignment - the text horizontal alignment
    • getText

      public String getText()
      Gets the text.
      Returns:
      the text
    • setText

      public void setText(String text)
      Sets the text for text fields.
      Parameters:
      text - the text
    • getBox

      public Rectangle getBox()
      Gets the field dimension and position.
      Returns:
      the field dimension and position
    • setBox

      public void setBox(Rectangle box)
      Sets the field dimension and position.
      Parameters:
      box - the field dimension and position
    • getRotation

      public int getRotation()
      Gets the field rotation.
      Returns:
      the field rotation
    • setRotation

      public void setRotation(int rotation)
      Sets the field rotation. This value should be the same as the page rotation where the field will be shown.
      Parameters:
      rotation - the field rotation
    • setRotationFromPage

      public void setRotationFromPage(Rectangle page)
      Convenience method to set the field rotation the same as the page rotation.
      Parameters:
      page - the page
    • getVisibility

      public int getVisibility()
      Gets the field visibility flag.
      Returns:
      the field visibility flag
    • setVisibility

      public void setVisibility(int visibility)
      Sets the field visibility flag. This flags can be one of VISIBLE, HIDDEN, VISIBLE_BUT_DOES_NOT_PRINT and HIDDEN_BUT_PRINTABLE.
      Parameters:
      visibility - field visibility flag
    • getFieldName

      public String getFieldName()
      Gets the field name.
      Returns:
      the field name
    • setFieldName

      public void setFieldName(String fieldName)
      Sets the field name.
      Parameters:
      fieldName - the field name. If null only the widget keys will be included in the field allowing it to be used as a kid field.
    • getAlternateFieldName

      public String getAlternateFieldName()
      Gets the alternate field name. (PDF attribute TU)
      Returns:
      the alternate field name
    • setAlternateFieldName

      public void setAlternateFieldName(String alternateFieldName)
      Sets the alternateFieldName field name.
      Parameters:
      alternateFieldName - the alternate field name.
    • getMappingName

      public String getMappingName()
      Gets the mapping name. (PDF attribute TM)
      Returns:
      the mapping field name
    • setMappingName

      public void setMappingName(String mappingName)
      Sets the mapping name. (PDF TM)
      Parameters:
      mappingName - the mapping name.
    • getOptions

      public int getOptions()
      Gets the option flags.
      Returns:
      the option flags
    • setOptions

      public void setOptions(int options)
      Sets the option flags. The option flags can be a combination by oring of READ_ONLY, REQUIRED, MULTILINE, DO_NOT_SCROLL, PASSWORD, FILE_SELECTION, DO_NOT_SPELL_CHECK and EDIT.
      Parameters:
      options - the option flags
    • getMaxCharacterLength

      public int getMaxCharacterLength()
      Gets the maximum length of the field's text, in characters.
      Returns:
      the maximum length of the field's text, in characters.
    • setMaxCharacterLength

      public void setMaxCharacterLength(int maxCharacterLength)
      Sets the maximum length of the field's text, in characters. It is only meaningful for text fields.
      Parameters:
      maxCharacterLength - the maximum length of the field's text, in characters
    • getWriter

      public PdfWriter getWriter()
      Getter for property writer.
      Returns:
      Value of property writer.
    • setWriter

      public void setWriter(PdfWriter writer)
      Setter for property writer.
      Parameters:
      writer - New value of property writer.