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
Base class for fields which use "Variable Text".
These fields construct an appearance stream dynamically at viewing time.
- Author:
- Ben Litchfield
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionGet the default appearance.Get the default style string.int
getQ()
This will get the 'quadding' or justification of the text to be displayed.Get the fields rich text value.protected final 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, getWidget, getWidgets, importFDF, setActions, setWidgets
Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDField
getAcroForm, getActions, getAlternateFieldName, getCOSObject, getFullyQualifiedName, getInheritableAttribute, getMappingName, getParent, getPartialName, getValueAsString, isNoExport, isReadOnly, isRequired, setAlternateFieldName, setFieldFlags, setMappingName, setNoExport, setPartialName, setReadOnly, setRequired, setValue, toString
-
Field Details
-
QUADDING_LEFT
public static final int QUADDING_LEFT- See Also:
-
QUADDING_CENTERED
public static final int QUADDING_CENTERED- See Also:
-
QUADDING_RIGHT
public static final int QUADDING_RIGHT- See Also:
-
-
Method Details
-
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
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
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
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
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
Set the fields rich text value.Setting the rich text value will not generate the appearance for the field.
Providing null as the value will remove the default style string.
You can setPDAcroForm.setNeedAppearances(Boolean)
to signal a conforming reader to generate the appearance stream.- Parameters:
richTextValue
- a rich text string
-
getStringOrStream
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
-