Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.interactive.form

public abstract Class PDVariableText

extends PDTerminalField
Class Inheritance
Known Direct Subclasses
org.apache.pdfbox.pdmodel.interactive.form.PDChoice, org.apache.pdfbox.pdmodel.interactive.form.PDTextField
Imports
java.io.IOException, org.apache.pdfbox.cos.COSBase, .COSDictionary, .COSName, .COSNumber, .COSStream, .COSString, org.apache.pdfbox.pdmodel.PDResources, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget

Base class for fields which use "Variable Text". These fields construct an appearance stream dynamically at viewing time.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
pack-priv
PDVariableText(PDAcroForm
The acroform.
acroForm
)

pack-priv
PDVariableText(PDAcroForm
The form that this field is part of.
acroForm
,
COSDictionary
the PDF object to represent as a field.
field
,
PDNonTerminalField
the parent node of the node
parent
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the DA element of the dictionary object
getDefaultAppearance
()

Get the default appearance.

pack-priv PDDefaultAppearanceString

Returns:

the DA element of the dictionary object
getDefaultAppearanceString
()

Get the default appearance.

public String

Returns:

the DS element of the dictionary object
getDefaultStyleString
()

Get the default style string.

public int

Returns:

The justification of the text strings.
getQ
()

This will get the 'quadding' or justification of the text to be displayed.

public String

Returns:

the rich text value string
getRichTextValue
()

Get the fields rich text value.

protected final String

Returns:

the text stream
getStringOrStream
(COSBase
the potential text or text stream
base
)

Get a text as text stream.

public void
setDefaultAppearance(String
a string describing the default appearance
daValue
)

Set the default appearance.

public void
setDefaultStyleString(String
a string describing the default style.
defaultStyleString
)

Set the default style string.

public void
setQ(int
The new text justification.
q
)

This will set the quadding/justification of the text.

public void
setRichTextValue(String
a rich text string
richTextValue
)

Set the fields rich text value.

Inherited from org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField:
applyChangeconstructAppearancesexportFDFgetFieldFlagsgetFieldTypegetWidgetsimportFDFsetActionssetWidgets

Field Detail

QUADDING_CENTEREDback to summary
public static final int QUADDING_CENTERED
QUADDING_LEFTback to summary
public static final int QUADDING_LEFT
QUADDING_RIGHTback to summary
public static final int QUADDING_RIGHT

Constructor Detail

PDVariableTextback to summary
pack-priv PDVariableText(PDAcroForm acroForm)
Parameters
acroForm:PDAcroForm

The acroform.

See Also
PDTerminalField#PDTerminalField(PDAcroForm)
PDVariableTextback to summary
pack-priv PDVariableText(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)

Constructor.

Parameters
acroForm:PDAcroForm

The form that this field is part of.

field:COSDictionary

the PDF object to represent as a field.

parent:PDNonTerminalField

the parent node of the node

Method Detail

getDefaultAppearanceback to summary
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:String

the DA element of the dictionary object

getDefaultAppearanceStringback to summary
pack-priv PDDefaultAppearanceString getDefaultAppearanceString() throws 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:PDDefaultAppearanceString

the DA element of the dictionary object

getDefaultStyleStringback to summary
public String getDefaultStyleString()

Get the default style string. The default style string defines the default style for rich text fields.

Returns:String

the DS element of the dictionary object

getQback to summary
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:int

The justification of the text strings.

getRichTextValueback to summary
public String getRichTextValue()

Get the fields rich text value.

Returns:String

the rich text value string

getStringOrStreamback to summary
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:COSBase

the potential text or text stream

Returns:String

the text stream

setDefaultAppearanceback to summary
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:String

a string describing the default appearance

setDefaultStyleStringback to summary
public void setDefaultStyleString(String defaultStyleString)

Set the default style string. Providing null as the value will remove the default style string.

Parameters
defaultStyleString:String

a string describing the default style.

setQback to summary
public void setQ(int q)

This will set the quadding/justification of the text. See QUADDING constants.

Parameters
q:int

The new text justification.

setRichTextValueback to summary
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:String

a rich text string