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.
    • Constructor Detail

      • PDVariableText

        PDVariableText​(PDAcroForm acroForm,
                       COSDictionary field,
                       PDNonTerminalField parent)
        Constructor.
        Parameters:
        acroForm - The form that this field is part of.
        field - the PDF object to represent as a field.
        parent - the parent node of the node
    • Method Detail

      • getDefaultAppearance

        public java.lang.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
      • getDefaultAppearanceString

        PDDefaultAppearanceString getDefaultAppearanceString()
                                                      throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • setDefaultAppearance

        public void setDefaultAppearance​(java.lang.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 java.lang.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​(java.lang.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 java.lang.String getRichTextValue()
                                          throws java.io.IOException
        Get the fields rich text value.
        Returns:
        the rich text value string
        Throws:
        java.io.IOException - if the field dictionary entry is not a text type
      • setRichTextValue

        public void setRichTextValue​(java.lang.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 java.lang.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