com.aspose.pdf

Interfaces

Classes

Enums

Exceptions

com.aspose.pdf

Class 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  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.

    See Also:
    TextFragmentAbsorber, IDocument
    • Constructor Detail

      • TextFragmentState

        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:
        fragment - Text fragment object.
    • Method Detail

      • getCharacterSpacing

        public float getCharacterSpacing()

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

        Overrides:
        getCharacterSpacing in class TextState
        Returns:
        float value
      • setCharacterSpacing

        public void setCharacterSpacing(float value)

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

        Overrides:
        setCharacterSpacing in class TextState
        Parameters:
        value - float value
      • getHorizontalScaling

        public float getHorizontalScaling()

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

        Overrides:
        getHorizontalScaling in class TextState
        Returns:
        float value
      • setHorizontalScaling

        public void setHorizontalScaling(float value)

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

        Overrides:
        setHorizontalScaling in class TextState
        Parameters:
        value - float value
      • getWordSpacing

        public float getWordSpacing()

        Gets word spacing of the text.

        Overrides:
        getWordSpacing in class TextState
        Returns:
        float value
      • setWordSpacing

        public void setWordSpacing(float value)

        Sets word spacing of the text.

        Overrides:
        setWordSpacing in class TextState
        Parameters:
        value - float value
      • getRenderingMode

        public int getRenderingMode()

        Gets or sets rendering mode of the text.

        Overrides:
        getRenderingMode in class TextState
        Returns:
        TextRenderingMode element
        See Also:
        TextRenderingMode
      • setRenderingMode

        public void setRenderingMode(int value)

        Gets or sets rendering mode of the text.

        Overrides:
        setRenderingMode in class TextState
        Parameters:
        value - TextRenderingMode element
        See Also:
        TextRenderingMode
      • isSubscript

        public boolean isSubscript()

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

        Overrides:
        isSubscript in class TextState
        Returns:
        boolean value
      • setSubscript

        public void setSubscript(boolean value)

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

        Overrides:
        setSubscript in class TextState
        Parameters:
        value - boolean value
      • isInvisible

        public boolean isInvisible()

        Gets invisibility of the text.

        Overrides:
        isInvisible in class TextState
        Returns:
        boolean value
      • setInvisible

        public void setInvisible(boolean value)

        Sets invisibility of the text.

        Overrides:
        setInvisible in class TextState
        Parameters:
        value - boolean value
      • isSuperscript

        public boolean isSuperscript()

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

        Overrides:
        isSuperscript in class TextState
        Returns:
        value boolean value
      • setSuperscript

        public void setSuperscript(boolean value)

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

        Overrides:
        setSuperscript in class TextState
        Parameters:
        value - 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 object
      • getLineSpacing

        public float getLineSpacing()

        Gets line spacing of the text.

        Overrides:
        getLineSpacing in class TextState
        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.

      • setLineSpacing

        public void setLineSpacing(float value)

        Sets line spacing of the text.

        Overrides:
        setLineSpacing in class TextState
        Parameters:
        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.

      • getForegroundColor

        public Color getForegroundColor()

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

        Overrides:
        getForegroundColor in class TextState
        Returns:
        Color object
      • setForegroundColor

        public void setForegroundColor(Color value)

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

        Overrides:
        setForegroundColor in class TextState
        Parameters:
        value - Color object
      • getStrokingColor

        public Color getStrokingColor()

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

        Overrides:
        getStrokingColor in class TextState
        Returns:
        Color instance
      • setStrokingColor

        public void setStrokingColor(Color value)

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

        Overrides:
        setStrokingColor in class TextState
        Parameters:
        value - Color instance
      • getBackgroundColor

        public Color getBackgroundColor()

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

        Overrides:
        getBackgroundColor in class TextState
        Returns:
        value Color object
      • setBackgroundColor

        public void setBackgroundColor(Color value)

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

        Overrides:
        setBackgroundColor in class TextState
        Parameters:
        value - Color value
      • getUnderline

        public boolean getUnderline()

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

        Returns:
        boolean value
      • setUnderline

        public void setUnderline(boolean value)

        Sets underline for the text, represented by the TextFragment object

        Overrides:
        setUnderline in class TextState
        Parameters:
        value - boolean value
      • setStrikeOut

        public void setStrikeOut(boolean value)

        Sets strikeout for the text, represented by the TextFragment object

        Overrides:
        setStrikeOut in class TextState
        Parameters:
        value - boolean value
      • getFontStyle

        public int getFontStyle()

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

        Overrides:
        getFontStyle in class TextState
        Returns:
        FontStyles element
        See Also:
        FontStyles
      • setFontStyle

        public void setFontStyle(int value)

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

        Overrides:
        setFontStyle in class TextState
        Parameters:
        value - int value
        See Also:
        FontStyles
      • getFont

        public Font getFont()

        Gets font of the text, represented by the TextFragment object

        Overrides:
        getFont in class TextState
        Returns:
        Font value
      • setFont

        public void setFont(Font value)

        Sets font of the text, represented by the TextFragment object

        Overrides:
        setFont in class TextState
        Parameters:
        value - Font value
      • getFontSize

        public float getFontSize()

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

        Overrides:
        getFontSize in class TextState
        Returns:
        float value
      • setFontSize

        public void setFontSize(float value)

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

        Overrides:
        setFontSize in class TextState
        Parameters:
        value - float value
      • getHorizontalAlignment

        public int 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.

        Overrides:
        getHorizontalAlignment in class TextState
        Returns:
        HorizontalAlignment value
        See Also:
        HorizontalAlignment
      • setHorizontalAlignment

        public void setHorizontalAlignment(int 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.

        Overrides:
        setHorizontalAlignment in class TextState
        Parameters:
        value - HorizontalAlignment value
        See Also:
        HorizontalAlignment
      • getFormattingOptions

        public TextFormattingOptions getFormattingOptions()

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

        Returns:
        TextFormattingOptions instance
      • setFormattingOptions

        public void setFormattingOptions(TextFormattingOptions value)

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

        Parameters:
        value - TextFormattingOptions instance
      • getTextHeight

        public float getTextHeight()

        Gets text height, represented by the TextFragment object

        Overrides:
        getTextHeight in class TextState
        Returns:
        float value
      • getRotation

        public double getRotation()

        Gets or sets rotation angle in degrees.

        Returns:
        double value
      • setRotation

        public void setRotation(double value)

        Gets or sets rotation angle in degrees.

        Parameters:
        value - double value
      • getDrawTextRectangleBorder

        public boolean getDrawTextRectangleBorder()
      • setDrawTextRectangleBorder

        public void setDrawTextRectangleBorder(boolean value)
      • measureString

        public double measureString(String str)

        Measures the string.

        Overrides:
        measureString in class TextState
        Parameters:
        str - The string.
        Returns:
        double value
      • applyChangesFrom

        public void applyChangesFrom(TextState textState)

        Applies settings from another textState

        Overrides:
        applyChangesFrom in class TextState
        Parameters:
        textState - Text state object.

        Only those properties will be copied that were changed explicitly.

      • applyChangesFrom

        public void applyChangesFrom(TextState textState,
                                     boolean groupChangesOnly)

        Applies settings from another textState

        Parameters:
        textState - Text state object.
        groupChangesOnly - if true inherit group changes only (without isolating the segments into single segment)