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 withTextStateobject.// 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(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");
TextFragmentState.Font property)
font size (TextFragmentState.FontSize property)
font style (TextFragmentState.FontStyle property)
foreground color (TextFragmentState.ForegroundColor property)
background color (TextFragmentState.BackgroundColor property)
Note that changing TextFragmentState properties may change inner 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 TextFragment.Segments collection unchanged, please change inner segments individually.
TextFragmentAbsorber,
IDocument| Constructor and Description |
|---|
TextFragmentState(TextFragment fragment)
Initializes new instance of the
TextFragmentState object with specified TextFragment object. |
| Modifier and Type | Method and Description |
|---|---|
void |
applyChangesFrom(TextState textState)
Applies settings from another textState
|
void |
applyChangesFrom(TextState textState,
boolean groupChangesOnly)
Applies settings from another textState
|
float |
getCharacterSpacing()
Gets character spacing of the text, represented by the
TextFragment object. |
Font |
getFont()
Gets font of the text, represented by the
TextFragment object
|
float |
getFontSize()
Gets font size of the text, represented by the
TextFragment object
|
Color |
getForegroundColor()
Gets foreground color of the text, represented by the
TextFragment object
|
int |
getHorizontalAlignment()
Gets or sets horizontal alignment for the text.
|
float |
getHorizontalScaling() |
float |
getLineSpacing()
Gets or sets line spacing of the text.
|
float |
getWordSpacing() |
void |
setBackgroundColor(Color value)
Sets background color of the text, represented by the
TextFragment object
|
void |
setCharacterSpacing(float value) |
void |
setFont(Font value)
Sets font of the text, represented by the
TextFragment object
|
void |
setFontSize(float value)
Sets font size of the text, represented by the
TextFragment object
|
void |
setFontStyle(int value)
Sets font style of the text, represented by the
TextFragment object
|
void |
setForegroundColor(Color value)
Sets foreground color of the text, represented by the
TextFragment object
|
void |
setHorizontalAlignment(int value) |
void |
setHorizontalScaling(float value) |
void |
setLineSpacing(float value) |
void |
setUnderline(boolean value)
Sets underline for the text, represented by the
TextFragment object
|
void |
setWordSpacing(float value) |
calculateFontSize, getBackgroundColor, getUnderline, setBackgroundColorpublic TextFragmentState(TextFragment fragment)
Initializes new instance of the TextFragmentState object with specified TextFragment object.
This TextFragmentState initialization is not supported.
TextFragmentState is only available with TextFragment.TextState property.
public float getCharacterSpacing()
Gets character spacing of the text, represented by the TextFragment object.
getCharacterSpacing in class TextStatepublic void setCharacterSpacing(float value)
setCharacterSpacing in class TextStatepublic float getHorizontalScaling()
getHorizontalScaling in class TextStatepublic void setHorizontalScaling(float value)
setHorizontalScaling in class TextStatepublic float getWordSpacing()
getWordSpacing in class TextStatepublic void setWordSpacing(float value)
setWordSpacing in class TextStatepublic float getLineSpacing()
Gets or sets line spacing of the text.
getLineSpacing in class TextStatepublic void setLineSpacing(float value)
setLineSpacing in class TextStatepublic Color getForegroundColor()
Gets foreground color of the text, represented by the TextFragment object
getForegroundColor in class TextStatepublic void setForegroundColor(Color value)
Sets foreground color of the text, represented by the TextFragment object
setForegroundColor in class TextStatepublic void setBackgroundColor(Color value)
Sets background color of the text, represented by the TextFragment object
setBackgroundColor in class TextStatepublic void setUnderline(boolean value)
Sets underline for the text, represented by the TextFragment object
setUnderline in class TextStatepublic void setFontStyle(int value)
Sets font style of the text, represented by the TextFragment object
setFontStyle in class TextStatepublic Font getFont()
Gets font of the text, represented by the TextFragment object
public void setFont(Font value)
Sets font of the text, represented by the TextFragment object
public float getFontSize()
Gets font size of the text, represented by the TextFragment object
getFontSize in class TextStatepublic void setFontSize(float value)
Sets font size of the text, represented by the TextFragment object
setFontSize in class TextStatepublic int getHorizontalAlignment()
Gets or sets horizontal alignment for the text.
getHorizontalAlignment in class TextStatepublic void setHorizontalAlignment(int value)
setHorizontalAlignment in class TextStatepublic void applyChangesFrom(TextState textState)
Applies settings from another textState
applyChangesFrom in class TextStatetextState - public void applyChangesFrom(TextState textState, boolean groupChangesOnly)
Applies settings from another textState
textState - groupChangesOnly - if true inherit group changes only (without isolating the segments into single segment)Copyright © 2018 Aspose. All Rights Reserved.