TextFragmentState

Inheritance: java.lang.Object, com.aspose.pdf.TextState

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 ```
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 ( 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.

Constructors

Constructor Description
TextFragmentState(TextFragment fragment) Initializes new instance of the TextFragmentState object with specified TextFragment object.

Methods

Method Description
getCharacterSpacing() Gets character spacing of the text, represented by the TextFragment object.
setCharacterSpacing(float value) Sets character spacing of the text, represented by the TextFragment object.
getHorizontalScaling() Gets horizontal scaling of the text, represented by the TextFragment object.
setHorizontalScaling(float value) Sets horizontal scaling of the text, represented by the TextFragment object.
getWordSpacing() Gets word spacing of the text.
setWordSpacing(float value) Sets word spacing of the text.
getRenderingMode() Gets or sets rendering mode of the text.
setRenderingMode(int value) Gets or sets rendering mode of the text.
isSubscript() Gets or sets subscript of the text, represented by the TextFragment object.
setSubscript(boolean value) Gets or sets subscript of the text, represented by the TextFragment object.
isInvisible() Gets invisibility of the text.
setInvisible(boolean value) Sets invisibility of the text.
isSuperscript() Gets or sets superscript of the text, represented by the TextFragment object.
setSuperscript(boolean value) Gets or sets superscript of the text, represented by the TextFragment object.
getTabStops() Gets tabstops for the text.
getLineSpacing() Gets line spacing of the text.
setLineSpacing(float value) Sets line spacing of the text.
getForegroundColor() Gets foreground color of the text, represented by the TextFragment object
setForegroundColor(Color value) Sets foreground color of the text, represented by the TextFragment object
getStrokingColor() Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)
setStrokingColor(Color value) Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)
getBackgroundColor() Sets background color of the text, represented by the TextFragment object
setBackgroundColor(Color value) Sets background color of the text, represented by the TextFragment object
isUnderline() Gets or sets underline for the text, represented by the TextFragment object
setUnderline(boolean value) Sets underline for the text, represented by the TextFragment object
setStrikeOut(boolean value) Sets strikeout for the text, represented by the TextFragment object
getFontStyle() Sets font style of the text, represented by the TextFragment object
setFontStyle(int value) Sets font style of the text, represented by the TextFragment object
getFont() Gets font of the text, represented by the TextFragment object
setFont(Font value) Sets font of the text, represented by the TextFragment object
getFontSize() Gets font size of the text, represented by the TextFragment object
setFontSize(float value) Sets font size of the text, represented by the TextFragment object
getHorizontalAlignment() Gets horizontal alignment for the text.
setHorizontalAlignment(HorizontalAlignment value) Sets horizontal alignment for the text.
getFormattingOptions() Gets or sets formatting options.
setFormattingOptions(TextFormattingOptions value) Gets or sets formatting options.
getTextHeight() Gets text height, represented by the TextFragment object
getRotation() Gets or sets rotation angle in degrees.
setRotation(double value) Gets or sets rotation angle in degrees.
getDrawTextRectangleBorder() Gets if text rectangle border drawn flag.
setDrawTextRectangleBorder(boolean value) Sets if text rectangle border drawn flag.
measureString(String str) Measures the string.
applyChangesFrom(TextState textState) Applies settings from another textState
applyChangesFrom(TextState textState, boolean groupChangesOnly) Applies settings from another textState

TextFragmentState(TextFragment fragment)

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.

Parameters:

Parameter Type Description
fragment TextFragment Text fragment object.

getCharacterSpacing()

public float getCharacterSpacing()

Gets character spacing of the text, represented by the TextFragment object.

Returns: float - float value

setCharacterSpacing(float value)

public void setCharacterSpacing(float value)

Sets character spacing of the text, represented by the TextFragment object.

Parameters:

Parameter Type Description
value float float value

getHorizontalScaling()

public float getHorizontalScaling()

Gets horizontal scaling of the text, represented by the TextFragment object.

Returns: float - float value

setHorizontalScaling(float value)

public void setHorizontalScaling(float value)

Sets horizontal scaling of the text, represented by the TextFragment object.

Parameters:

Parameter Type Description
value float float value

getWordSpacing()

public float getWordSpacing()

Gets word spacing of the text.

Returns: float - float value

setWordSpacing(float value)

public void setWordSpacing(float value)

Sets word spacing of the text.

Parameters:

Parameter Type Description
value float float value

getRenderingMode()

public int getRenderingMode()

Gets or sets rendering mode of the text.

Returns: int

setRenderingMode(int value)

public void setRenderingMode(int value)

Gets or sets rendering mode of the text.

Parameters:

Parameter Type Description
value int

isSubscript()

public boolean isSubscript()

Gets or sets subscript of the text, represented by the TextFragment object.

Returns: boolean - boolean value

setSubscript(boolean value)

public void setSubscript(boolean value)

Gets or sets subscript of the text, represented by the TextFragment object.

Parameters:

Parameter Type Description
value boolean boolean value

isInvisible()

public boolean isInvisible()

Gets invisibility of the text.

Returns: boolean - boolean value

setInvisible(boolean value)

public void setInvisible(boolean value)

Sets invisibility of the text.

Parameters:

Parameter Type Description
value boolean boolean value

isSuperscript()

public boolean isSuperscript()

Gets or sets superscript of the text, represented by the TextFragment object.

Returns: boolean - value boolean value

setSuperscript(boolean value)

public void setSuperscript(boolean value)

Gets or sets superscript of the text, represented by the TextFragment object.

Parameters:

Parameter Type Description
value boolean boolean value

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 TextFragment initialization. Tabstops must be constructed before the text.

Returns: TabStops - TabStops object

getLineSpacing()

public float getLineSpacing()

Gets line spacing of the text.

Returns: float - 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.

setLineSpacing(float value)

public void setLineSpacing(float value)

Sets line spacing of the text.

Parameters:

Parameter Type Description
value float 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. |

getForegroundColor()

public Color getForegroundColor()

Gets foreground color of the text, represented by the TextFragment object

Returns: Color - Color object

setForegroundColor(Color value)

public void setForegroundColor(Color value)

Sets foreground color of the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value Color Color object

getStrokingColor()

public Color getStrokingColor()

Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)

Returns: Color

setStrokingColor(Color value)

public void setStrokingColor(Color value)

Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)

Parameters:

Parameter Type Description
value Color

getBackgroundColor()

public Color getBackgroundColor()

Sets background color of the text, represented by the TextFragment object

Returns: Color - value Color object

setBackgroundColor(Color value)

public void setBackgroundColor(Color value)

Sets background color of the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value Color

isUnderline()

public boolean isUnderline()

Gets or sets underline for the text, represented by the TextFragment object

Returns: boolean - boolean value

setUnderline(boolean value)

public void setUnderline(boolean value)

Sets underline for the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value boolean boolean value

setStrikeOut(boolean value)

public void setStrikeOut(boolean value)

Sets strikeout for the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value boolean boolean value

getFontStyle()

public int getFontStyle()

Sets font style of the text, represented by the TextFragment object

Returns: int - FontStyles element

setFontStyle(int value)

public void setFontStyle(int value)

Sets font style of the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value int int value

getFont()

public Font getFont()

Gets font of the text, represented by the TextFragment object

Returns: Font - Font value

setFont(Font value)

public void setFont(Font value)

Sets font of the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value Font Font value

getFontSize()

public float getFontSize()

Gets font size of the text, represented by the TextFragment object

Returns: float - float value

setFontSize(float value)

public void setFontSize(float value)

Sets font size of the text, represented by the TextFragment object

Parameters:

Parameter Type Description
value float float value

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 - HorizontalAlignment value

setHorizontalAlignment(HorizontalAlignment value)

public void setHorizontalAlignment(HorizontalAlignment value)

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.

Parameters:

Parameter Type Description
value HorizontalAlignment HorizontalAlignment value

getFormattingOptions()

public TextFormattingOptions getFormattingOptions()

Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.

Returns: TextFormattingOptions - TextFormattingOptions instance

setFormattingOptions(TextFormattingOptions value)

public void setFormattingOptions(TextFormattingOptions value)

Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.

Parameters:

Parameter Type Description
value TextFormattingOptions TextFormattingOptions instance

getTextHeight()

public float getTextHeight()

Gets text height, represented by the TextFragment object

Returns: float - float value

getRotation()

public double getRotation()

Gets or sets rotation angle in degrees.

Returns: double - double value

setRotation(double value)

public void setRotation(double value)

Gets or sets rotation angle in degrees.

Parameters:

Parameter Type Description
value double double value

getDrawTextRectangleBorder()

public boolean getDrawTextRectangleBorder()

Gets if text rectangle border drawn flag.

Returns: boolean - boolean value

setDrawTextRectangleBorder(boolean value)

public void setDrawTextRectangleBorder(boolean value)

Sets if text rectangle border drawn flag.

Parameters:

Parameter Type Description
value boolean boolean value

measureString(String str)

public double measureString(String str)

Measures the string.

Parameters:

Parameter Type Description
str java.lang.String The string.

Returns: double - double value, Width of the string.

applyChangesFrom(TextState textState)

public void applyChangesFrom(TextState textState)

Applies settings from another textState

Parameters:

Parameter Type Description
textState TextState Text state object.

Only those properties will be copied that were changed explicitly. |

applyChangesFrom(TextState textState, boolean groupChangesOnly)

public void applyChangesFrom(TextState textState, boolean groupChangesOnly)

Applies settings from another textState

Parameters:

Parameter Type Description
textState TextState Text state object.
groupChangesOnly boolean if true inherit group changes only (without isolating the segments into single segment)