org.apache.pdfbox.pdmodel.interactive.form

## Class PDVariableText

- java.lang.Object
- - org.apache.pdfbox.pdmodel.interactive.form.PDField
  - - org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField
    - - org.apache.pdfbox.pdmodel.interactive.form.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 Summary

Fields
`static int` `QUADDING_CENTERED`
`static int` `QUADDING_LEFT`
`static int` `QUADDING_RIGHT`

### Method Summary

All Methods Instance Methods Concrete Methods
`String` `getDefaultAppearance()` Get the default appearance.
`String` `getDefaultStyleString()` Get the default style string.
`int` `getQ()` This will get the 'quadding' or justification of the text to be displayed.
`String` `getRichTextValue()` Get the fields rich text value.
`protected String` `getStringOrStream(COSBase base)` Get a text as text stream.
`void` `setDefaultAppearance(String daValue)` Set the default appearance.
`void` `setDefaultStyleString(String defaultStyleString)` Set the default style string.
`void` `setQ(int q)` This will set the quadding/justification of the text.
`void` `setRichTextValue(String richTextValue)` Set the fields rich text value.

### Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField

`applyChange, getFieldFlags, getFieldType, getWidgets, importFDF, setActions, setWidgets`

### Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDField

`equals, getAcroForm, getActions, getAlternateFieldName, getCOSObject, getFullyQualifiedName, getInheritableAttribute, getMappingName, getParent, getPartialName, getValueAsString, hashCode, isNoExport, isReadOnly, isRequired, setAlternateFieldName, setFieldFlags, setMappingName, setNoExport, setPartialName, setReadOnly, setRequired, setValue, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### QUADDING_LEFT

    public static final int QUADDING_LEFT

See Also:
  Constant Field Values

#### QUADDING_CENTERED

    public static final int QUADDING_CENTERED

See Also:
  Constant Field Values

#### QUADDING_RIGHT

    public static final int QUADDING_RIGHT

See Also:
  Constant Field Values

### Method Detail

#### 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()

Get the fields rich text value.

Returns:
  the rich text value string

#### 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