TextFragmentState
Inheritance: java.lang.Object, com.aspose.pdf.TextState com.aspose.pdf.TextFragmentState, com.aspose.pdf.TextState, com.aspose.pdf.TextFragmentState
public final class TextFragmentState extends TextState
Represents a text state of a text fragment.
The example demonstrates how to change text color and font size of the text with {@code TextState} object. // Open document Document doc = new Document("D:\\Tests\\input.pdf"); // Create TextFragmentAbsorber object to find all "hello world" text occurrences TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world"); // Accept the absorber for first page doc.getPages().get(1).accept(absorber); // Change foreground color of the first text occurrence absorber.TgetextFragments().get(1).getTextState().setForegroundColor ( java.awt.Color.RED); // Change font size of the first text occurrence absorber.getTextFragments().get(1).getTextState().setFontSize ( 15); // Save document doc.save("D:\\Tests\\output.pdf"); Provides a way to change following properties of the text: font ({@code TextFragmentState.Font} property) font size ({@code TextFragmentState.FontSize} property) font style ( {@code TextFragmentState.FontStyle} property) foreground color ( {@code TextFragmentState.ForegroundColor} property) background color ( {@code TextFragmentState.BackgroundColor} property)
Note that changing {@code TextFragmentState} properties may change inner {@code TextFragment.Segments} collection because TextFragment is an aggregate object and it may rearrange internal segments or merge them into single segment. If your requirement is to leave the {@code TextFragment.Segments} collection unchanged, please change inner segments individually.
@see TextFragmentAbsorber @see IDocumentConstructors
| Constructor | Description |
|---|---|
| TextFragmentState | Initializes new instance of the {@code TextFragmentState} object with specified {@code TextFragment} object. This {@code TextFragmentState} initialization is not supported. TextFragmentState is only available with {@code TextFragment.TextState} property. |
Methods
| Method | Description |
|---|---|
| applyChangesFrom | Applies settings from another textState |
| applyChangesFrom | Applies settings from another textState |
| getBackgroundColor | Sets background color of the text, represented by the {@code TextFragment} object |
| getCharacterSpacing | Gets character spacing of the text, represented by the {@code TextFragment} object. |
| getCoordinateOrigin | Gets or sets text CoordinateOrigin. If CoordinateOrigin is Descender, the text Y coordinate corresponds to the font’s lowest point. If CoordinateOrigin is BaseLine, the text Y coordinate corresponds to the font’s baseline. The default value is Descender. If the font’s Descent value is too big, text can be rendered higher than other fonts. In this case, CoordinateOrigin BaseLine can be selected for better text rendering. |
| getDrawTextRectangleBorder | Gets if text rectangle border drawn flag. |
| getFont | Gets font of the text, represented by the {@code TextFragment} object |
| getFontSize | Gets font size of the text, represented by the {@code TextFragment} object |
| getFontStyle | Sets font style of the text, represented by the {@code TextFragment} object |
| getForegroundColor | Gets foreground color of the text, represented by the {@code TextFragment} object |
| getFormattingOptions | Gets or sets formatting options. Setting of the options will be effective in generator scenarios only. |
| getHorizontalAlignment | Gets horizontal alignment for the text. HorizontalAlignment.None is equal to HorizontalAlignment.Left. Note that TextFragmentState.VerticalAlignment property works in new document generation scenarios only. |
| getHorizontalScaling | Gets horizontal scaling of the text, represented by the {@code TextFragment} object. |
| getLineSpacing | Gets line spacing of the text. |
| getRenderingMode | Gets or sets rendering mode of the text. |
| getRotation | Gets or sets rotation angle in degrees. |
| getStrokingColor | Gets or sets color stroking operations of {@code TextFragment} rendering (stroke text, rectangle border) |
| getTabStops | Gets tabstops for the text. Note that Tabstops property works in new document generation scenarios only. Tabstops may be added during {@code TextFragment} initialization. Tabstops must be constructed before the text. |
| getTextHeight | Gets text height, represented by the {@code TextFragment} object |
| getWordSpacing | Gets word spacing of the text. |
| isFitRectangle | Checks if input string could be placed inside defined rectangle. |
| isInvisible | Gets invisibility of the text. |
| isStrikeOut | Gets or sets strikeout for the text, represented by the {@link TextFragment} object |
| isSubscript | Gets or sets subscript of the text, represented by the {@code TextFragment} object. |
| isSuperscript | Gets or sets superscript of the text, represented by the {@code TextFragment} object. |
| isUnderline | Gets or sets underline for the text, represented by the {@link TextFragment} object |
| measureHeight | Measures character height. |
| measureString | Measures the string. |
| setBackgroundColor | Sets background color of the text, represented by the TextFragment object |
| setCharacterSpacing | Sets character spacing of the text, represented by the {@code TextFragment} object. |
| setCoordinateOrigin | Gets or sets text CoordinateOrigin. If CoordinateOrigin is Descender, the text Y coordinate corresponds to the font’s lowest point. If CoordinateOrigin is BaseLine, the text Y coordinate corresponds to the font’s baseline. The default value is Descender. If the font’s Descent value is too big, text can be rendered higher than other fonts. In this case, CoordinateOrigin BaseLine can be selected for better text rendering. |
| setDrawTextRectangleBorder | Sets if text rectangle border drawn flag. |
| setFont | Sets font of the text, represented by the {@code TextFragment} object |
| setFontSize | Sets font size of the text, represented by the {@code TextFragment} object |
| setFontStyle | Sets font style of the text, represented by the {@link TextFragment} object |
| setForegroundColor | Sets foreground color of the text, represented by the {@code TextFragment} object |
| setFormattingOptions | Gets or sets formatting options. Setting of the options will be effective in generator scenarios only. |
| setHorizontalAlignment | Sets horizontal alignment for the text. HorizontalAlignment.None is equal to HorizontalAlignment.Left. Note that TextFragmentState.VerticalAlignment property works in new document generation scenarios only. |
| setHorizontalScaling | Sets horizontal scaling of the text, represented by the {@code TextFragment} object. |
| setInvisible | Sets invisibility of the text. |
| setLineSpacing | Sets line spacing of the text. |
| setRenderingMode | Gets or sets rendering mode of the text. |
| setRotation | Gets or sets rotation angle in degrees. |
| setStrikeOut | Sets strikeout for the text, represented by the {@code TextFragment} object |
| setStrokingColor | Gets or sets color stroking operations of {@code TextFragment} rendering (stroke text, rectangle border) |
| setSubscript | Gets or sets subscript of the text, represented by the {@code TextFragment} object. |
| setSuperscript | Gets or sets superscript of the text, represented by the {@code TextFragment} object. |
| setUnderline | Sets underline for the text, represented by the {@code TextFragment} object |
| setWordSpacing | Sets word spacing of the text. |
TextFragmentState
Initializes new instance of the {@code TextFragmentState} object with specified {@code TextFragment} object. This {@code TextFragmentState} initialization is not supported. TextFragmentState is only available with {@code TextFragment.TextState} property.
applyChangesFrom
Applies settings from another textState
applyChangesFrom
Applies settings from another textState
getBackgroundColor
public Color getBackgroundColor()
Sets background color of the text, represented by the {@code TextFragment} object
Returns: value Color object
getCharacterSpacing
public float getCharacterSpacing()
Gets character spacing of the text, represented by the {@code TextFragment} object.
Returns: float value
getCoordinateOrigin
public CoordinateOrigin getCoordinateOrigin()
Gets or sets text CoordinateOrigin. If CoordinateOrigin is Descender, the text Y coordinate corresponds to the font’s lowest point. If CoordinateOrigin is BaseLine, the text Y coordinate corresponds to the font’s baseline. The default value is Descender. If the font’s Descent value is too big, text can be rendered higher than other fonts. In this case, CoordinateOrigin BaseLine can be selected for better text rendering.
Returns: CoordinateOrigin element
getDrawTextRectangleBorder
public boolean getDrawTextRectangleBorder()
Gets if text rectangle border drawn flag.
Returns: boolean value
getFont
public Font getFont()
Gets font of the text, represented by the {@code TextFragment} object
Returns: Font value
getFontSize
public float getFontSize()
Gets font size of the text, represented by the {@code TextFragment} object
Returns: float value
getFontStyle
public int getFontStyle()
Sets font style of the text, represented by the {@code TextFragment} object
Returns: FontStyles element @see FontStyles
getForegroundColor
public Color getForegroundColor()
Gets foreground color of the text, represented by the {@code TextFragment} object
Returns: Color object
getFormattingOptions
public TextFormattingOptions getFormattingOptions()
Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.
Returns: TextFormattingOptions instance
getHorizontalAlignment
public HorizontalAlignment getHorizontalAlignment()
Gets horizontal alignment for the text.
HorizontalAlignment.None is equal to HorizontalAlignment.Left. Note that TextFragmentState.VerticalAlignment property works in new document generation scenarios only.
Returns: HorizontalAlignment value @see HorizontalAlignment
getHorizontalScaling
public float getHorizontalScaling()
Gets horizontal scaling of the text, represented by the {@code TextFragment} object.
Returns: float value
getLineSpacing
public float getLineSpacing()
Gets line spacing of the text.
Returns: float value
Note that the value is not preserved as a text characteristic within the document. The LineSpacing property getter works for an object in case it was explicitly set previously with LineSpacing setter for those object. The property is used by runtime in context of current generation/modification process.
getRenderingMode
public TextRenderingMode getRenderingMode()
Gets or sets rendering mode of the text.
Returns: TextRenderingMode element
getRotation
public double getRotation()
Gets or sets rotation angle in degrees.
Returns: double value
getStrokingColor
public Color getStrokingColor()
Gets or sets color stroking operations of {@code TextFragment} rendering (stroke text, rectangle border)
Returns: Color instance
getTabStops
public TabStops getTabStops()
Gets tabstops for the text.
Note that Tabstops property works in new document generation scenarios only. Tabstops may be added during {@code TextFragment} initialization. Tabstops must be constructed before the text.
Returns: TabStops object
getTextHeight
public float getTextHeight()
Gets text height, represented by the {@code TextFragment} object
Returns: float value
getWordSpacing
public float getWordSpacing()
Gets word spacing of the text.
Returns: float value
isFitRectangle
Checks if input string could be placed inside defined rectangle.
isInvisible
public boolean isInvisible()
Gets invisibility of the text.
Returns: boolean value
isStrikeOut
public boolean isStrikeOut()
Gets or sets strikeout for the text, represented by the {@link TextFragment} object
Returns: boolean value
isSubscript
public boolean isSubscript()
Gets or sets subscript of the text, represented by the {@code TextFragment} object.
Returns: boolean value
isSuperscript
public boolean isSuperscript()
Gets or sets superscript of the text, represented by the {@code TextFragment} object.
Returns: value boolean value
isUnderline
public boolean isUnderline()
Gets or sets underline for the text, represented by the {@link TextFragment} object
Returns: boolean value
measureHeight
public final double measureHeight(char character)
Measures character height.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| character | Character to measure. |
Returns: Height of the character if we could get it from font; otherwise 0.
measureString
Measures the string.
setBackgroundColor
Sets background color of the text, represented by the TextFragment object
setCharacterSpacing
public void setCharacterSpacing(float value)
Sets character spacing of the text, represented by the {@code TextFragment} object.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | float value |
setCoordinateOrigin
Gets or sets text CoordinateOrigin. If CoordinateOrigin is Descender, the text Y coordinate corresponds to the font’s lowest point. If CoordinateOrigin is BaseLine, the text Y coordinate corresponds to the font’s baseline. The default value is Descender. If the font’s Descent value is too big, text can be rendered higher than other fonts. In this case, CoordinateOrigin BaseLine can be selected for better text rendering.
setDrawTextRectangleBorder
public void setDrawTextRectangleBorder(boolean value)
Sets if text rectangle border drawn flag.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean value |
setFont
Sets font of the text, represented by the {@code TextFragment} object
setFontSize
public void setFontSize(float value)
Sets font size of the text, represented by the {@code TextFragment} object
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | float value |
setFontStyle
public void setFontStyle(int value)
Sets font style of the text, represented by the {@link TextFragment} object
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | int value @see FontStyles |
setForegroundColor
Sets foreground color of the text, represented by the {@code TextFragment} object
setFormattingOptions
Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.
setHorizontalAlignment
Sets horizontal alignment for the text.
HorizontalAlignment.None is equal to HorizontalAlignment.Left. Note that TextFragmentState.VerticalAlignment property works in new document generation scenarios only.
setHorizontalScaling
public void setHorizontalScaling(float value)
Sets horizontal scaling of the text, represented by the {@code TextFragment} object.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | float value |
setInvisible
public void setInvisible(boolean value)
Sets invisibility of the text.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean value |
setLineSpacing
public void setLineSpacing(float value)
Sets line spacing of the text.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | float value Note that the value is not preserved as a text characteristic within the document. The LineSpacing property getter works for an object in case it was explicitly set previously with LineSpacing setter for those object. The property is used by runtime in context of current generation/modification process. |
setRenderingMode
Gets or sets rendering mode of the text.
setRotation
public void setRotation(double value)
Gets or sets rotation angle in degrees.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | double value |
setStrikeOut
public void setStrikeOut(boolean value)
Sets strikeout for the text, represented by the {@code TextFragment} object
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean value |
setStrokingColor
Gets or sets color stroking operations of {@code TextFragment} rendering (stroke text, rectangle border)
setSubscript
public void setSubscript(boolean value)
Gets or sets subscript of the text, represented by the {@code TextFragment} object.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean value |
setSuperscript
public void setSuperscript(boolean value)
Gets or sets superscript of the text, represented by the {@code TextFragment} object.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean value |
setUnderline
public void setUnderline(boolean value)
Sets underline for the text, represented by the {@code TextFragment} object
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean value |
setWordSpacing
public void setWordSpacing(float value)
Sets word spacing of the text.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | float value |