Class PDVariableText

All Implemented Interfaces:
COSObjectable
Direct Known Subclasses:
PDChoice, PDTextField

public abstract class PDVariableText extends PDTerminalField
Base class for fields which use "Variable Text". These fields construct an appearance stream dynamically at viewing time.
Author:
Ben Litchfield
  • Field Details

  • Method Details

    • getDefaultAppearance

      public String getDefaultAppearance()
      Get the default appearance. This is an inheritable attribute. The default appearance contains a set of default graphics and text operators to define the field?s text size and color.
      Returns:
      the DA element of the dictionary object
    • setDefaultAppearance

      public void setDefaultAppearance(String daValue)
      Set the default appearance. This will set the local default appearance for the variable text field only, not affecting a default appearance in the parent hierarchy. Providing null as the value will remove the local default appearance.

      This method can also be used to change the font of a field, by replacing the font name from this string with another font name found in the AcroForm default resources before calling setValue(String), see also this stackoverflow answer. For example, "/Helv 10 Tf 0 g" can be replaced with "/F1 10 Tf 0 g". Performance may go down (see PDFBOX-4508) if this is done for many fields and with a very large font (e.g. ArialUni); to avoid this, save and reload the file after changing all fields.

      Parameters:
      daValue - a string describing the default appearance
    • getDefaultStyleString

      public String getDefaultStyleString()
      Get the default style string. The default style string defines the default style for rich text fields.
      Returns:
      the DS element of the dictionary object
    • setDefaultStyleString

      public void setDefaultStyleString(String defaultStyleString)
      Set the default style string. Providing null as the value will remove the default style string.
      Parameters:
      defaultStyleString - a string describing the default style.
    • getQ

      public int getQ()
      This will get the 'quadding' or justification of the text to be displayed. This is an inheritable attribute.
      0 - Left (default)
      1 - Centered
      2 - Right
      Please see the QUADDING_CONSTANTS.
      Returns:
      The justification of the text strings.
    • setQ

      public void setQ(int q)
      This will set the quadding/justification of the text. See QUADDING constants.
      Parameters:
      q - The new text justification.
    • getRichTextValue

      public String getRichTextValue() throws IOException
      Get the fields rich text value.
      Returns:
      the rich text value string
      Throws:
      IOException - if the field dictionary entry is not a text type
    • setRichTextValue

      public void setRichTextValue(String richTextValue)
      Set the fields rich text value.

      Setting the rich text value will not generate the appearance for the field.
      You can set PDAcroForm.setNeedAppearances(Boolean) to signal a conforming reader to generate the appearance stream.

      Providing null as the value will remove the default style string.
      Parameters:
      richTextValue - a rich text string
    • getStringOrStream

      protected final String getStringOrStream(COSBase base)
      Get a text as text stream. Some dictionary entries allow either a text or a text stream.
      Parameters:
      base - the potential text or text stream
      Returns:
      the text stream