TextFragmentState

TextFragmentState class

Represents a text state of a text fragment.

public sealed class TextFragmentState : TextState

Constructors

Name Description
TextFragmentState(TextFragment) Initializes new instance of the TextFragmentState object with specified TextFragment object. This TextFragmentState initialization is not supported. TextFragmentState is only available with TextState property.

Properties

Name Description
override BackgroundColor { get; set; } Sets background color of the text, represented by the TextFragment object
override CharacterSpacing { get; set; } Gets or sets character spacing of the text, represented by the TextFragment object.
DrawTextRectangleBorder { get; set; } Gets or sets if text rectangle border drawn flag.
override Font { get; set; } Gets or sets font of the text, represented by the TextFragment object
override FontSize { get; set; } Gets or sets font size of the text, represented by the TextFragment object
override FontStyle { get; set; } Sets font style of the text, represented by the TextFragment object
override ForegroundColor { get; set; } Gets or sets foreground color of the text, represented by the TextFragment object
FormattingOptions { get; set; } Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.
override HorizontalAlignment { get; set; } Gets or sets horizontal alignment for the text.
override HorizontalScaling { get; set; } Gets or sets horizontal scaling of the text, represented by the TextFragment object.
override Invisible { get; set; } Gets or sets invisibility of the text.
override LineSpacing { get; set; } Gets or sets line spacing of the text.
override RenderingMode { get; set; } Gets or sets rendering mode of the text.
Rotation { get; set; } Gets or sets rotation angle in degrees.
override StrikeOut { set; } Sets strikeout for the text, represented by the TextFragment object
override StrokingColor { get; set; } Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)
override Subscript { get; set; } Gets or sets subscript of the text, represented by the TextFragment object.
override Superscript { get; set; } Gets or sets superscript of the text, represented by the TextFragment object.
TabStops { get; } Gets tabstops for the text.
override Underline { get; set; } Gets or sets underline for the text, represented by the TextFragment object
override WordSpacing { get; set; } Gets or sets word spacing of the text.

Methods

Name Description
override ApplyChangesFrom(TextState) Applies settings from another textState.
override MeasureString(string) Measures the string.

Fields

Name Description
readonly TabstopDefaultValue Default value of tabulation in widths of space character of default font.
readonly TabTag You can place this tag in text to declare tabulation.

Remarks

Provides a way to change following properties of the text: font (Font property) font size (FontSize property) font style (FontStyle property) foreground color (ForegroundColor property) background color (BackgroundColor property) Note that changing TextFragmentState properties may change inner 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 Segments collection unchanged, please change inner segments individually.

Examples

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.Pages[1].Accept(absorber);

// Change foreground color of the first text occurrence
absorber.TextFragments[1].TextState.ForegroundColor = Color.FromRgb(System.Drawing.Color.Red);
// Change font size of the first text occurrence
absorber.TextFragments[1].TextState.FontSize = 15;

// Save document
doc.Save(@"D:\Tests\output.pdf");  

See Also