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 withTextState
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(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
|
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
|
com.aspose.java.awt.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(com.aspose.java.awt.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(com.aspose.java.awt.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, setBackgroundColor
public 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 void setCharacterSpacing(float value)
setCharacterSpacing
in class TextState
public float getHorizontalScaling()
getHorizontalScaling
in class TextState
public void setHorizontalScaling(float value)
setHorizontalScaling
in class TextState
public float getWordSpacing()
getWordSpacing
in class TextState
public void setWordSpacing(float value)
setWordSpacing
in class TextState
public float getLineSpacing()
Gets or sets line spacing of the text.
getLineSpacing
in class TextState
public void setLineSpacing(float value)
setLineSpacing
in class TextState
public com.aspose.java.awt.Color getForegroundColor()
Gets foreground color of the text, represented by the TextFragment
object
getForegroundColor
in class TextState
public void setForegroundColor(com.aspose.java.awt.Color value)
Sets foreground color of the text, represented by the TextFragment
object
setForegroundColor
in class TextState
public void setBackgroundColor(com.aspose.java.awt.Color value)
Sets background color of the text, represented by the TextFragment
object
setBackgroundColor
in class TextState
public void setUnderline(boolean value)
Sets underline for the text, represented by the TextFragment
object
setUnderline
in class TextState
public void setFontStyle(int value)
Sets font style of the text, represented by the TextFragment
object
setFontStyle
in class TextState
public 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 TextState
public void setFontSize(float value)
Sets font size of the text, represented by the TextFragment
object
setFontSize
in class TextState
public int getHorizontalAlignment()
Gets or sets horizontal alignment for the text.
getHorizontalAlignment
in class TextState
public void setHorizontalAlignment(int value)
setHorizontalAlignment
in class TextState
public void applyChangesFrom(TextState textState)
Applies settings from another textState
applyChangesFrom
in class TextState
textState
- 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 © 2017 Aspose. All Rights Reserved.