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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
QUADDING_CENTERED
static int
QUADDING_LEFT
static int
QUADDING_RIGHT
-
Constructor Summary
Constructors Constructor Description PDVariableText(PDAcroForm acroForm)
PDVariableText(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDefaultAppearance()
Get the default appearance.(package private) PDDefaultAppearanceString
getDefaultAppearanceString()
Get the default appearance.java.lang.String
getDefaultStyleString()
Get the default style string.int
getQ()
This will get the 'quadding' or justification of the text to be displayed.java.lang.String
getRichTextValue()
Get the fields rich text value.protected java.lang.String
getStringOrStream(COSBase base)
Get a text as text stream.void
setDefaultAppearance(java.lang.String daValue)
Set the default appearance.void
setDefaultStyleString(java.lang.String defaultStyleString)
Set the default style string.void
setQ(int q)
This will set the quadding/justification of the text.void
setRichTextValue(java.lang.String richTextValue)
Set the fields rich text value.-
Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField
applyChange, constructAppearances, exportFDF, getFieldFlags, getFieldType, getWidget, getWidgets, importFDF, setActions, setWidgets
-
Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDField
findKid, fromDictionary, getAcroForm, getActions, getAlternateFieldName, getCOSObject, getFullyQualifiedName, getInheritableAttribute, getMappingName, getParent, getPartialName, getValueAsString, isNoExport, isReadOnly, isRequired, setAlternateFieldName, setFieldFlags, setMappingName, setNoExport, setPartialName, setReadOnly, setRequired, setValue, toString
-
-
-
-
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
-
-
Constructor Detail
-
PDVariableText
PDVariableText(PDAcroForm acroForm)
- Parameters:
acroForm
- The acroform.- See Also:
PDTerminalField(PDAcroForm)
-
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.
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
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
-
-