TextFragment
TextFragment is content element that represents а single-line text object.
Inserting a TextFragment
TextFragment is a content element that can be added in the Content collection of a IContainerElement such as RadFixedPage. There are several approaches that can be adopted.
Example 1 shows how you can initialize a TextFragment object and add it to a previously defined container.
Example 1: Create TextFragment and add it to container
TextFragment fragment = new TextFragment();
container.Content.Add(fragment);
Example 2 demonstrates how to use one of the factory methods of the ContentElementCollection, which create new text fragment and insert it into the respective container. Both methods return the actual TextFragment instance so you can modify it.
Example 2: Add TextFragment to container
TextFragment textFragment = container.Content.AddTextFragment();
TextFragment textFragmentWithText = container.Content.AddTextFragment("Text");
TextFragment represents a single line of text. In order to make your text "flows" in a document you should make sure all fragments you add can fit in a line or you can use FixedContentEditor.
The '\r' and '\n' characters don't have the usual meaning of "go to next line" when they are inserted into a PDF document and you cannot simply insert text containing these characters to produce multiline text. Instead, you should split the text and insert it line by line.
Modifying a TextFragment
TextFragment exposes the following properties that can modify the look of the represented text:
CharacterSpacing: The spacing between the characters in the text.
-
WordSpacing: The spacing between the words in the text.
Only space character (Unicode 0x32) is considered a word break in RadPdfProcessing's document model.
HorizontalScaling: The horizontal scaling that is applied to the characters.
Font: The font that is used to draw the text.
FontSize: The font size. The measurement unit used for font size is DIP. You can convert it to points or other units using the Unit class.
-
RenderingMode: Enumeration representing the way the text should be rendered. It can have one of the following values:
Fill: Fill text (the default value).
Stroke: Stroke text.
FillAndStroke: Fill, then stroke text.
None: Neither fill nor stroke text (invisible).
FillAndAddToClippingPath: Fill text and add to path for clipping (see above).
StrokeAndAddToClippingPath: Stroke text and add to path for clipping.
FillStrokeAndAddToClippingPath: Fill, then stroke text and add to path for clipping
AddToClippingPath: Add text to path for clipping.
TextRise: Specifies the distance, in unscaled text space units, to move the baseline up or down from its default location.
Fill: The color that is used to fill the text. The default value is Black.
Stroke: The color that is used to stroke text. The default value is Black.
StrokeThickness: The width of the stroke line.
-
StrokeLineCap: Specifies the shape, which is used at the ends of open paths, used to draw a letter, when they are stroked.
Flat: Flat line cap.
Round: Round line cap.
Square: Square line cap.
-
StrokeLineJoin: Specifies the shape to be used at the corners of paths that are stroked. Join styles are significant only at the points where consecutive segments of a path connect at an angle.
Bevel: Produces a diagonal corner.
Miter: Produces a sharp corner. If the segments meet at too sharp angle, a bevel join is used instead.
Round: Produces a smooth, circular arc between the lines.
StrokeDashArray: The pattern of dashes and gaps used to stroke paths.
StrokeDashOffset: The distance from the start of a line to the beginning of a dash pattern.
MiterLimit: The limit of the thickness of the join on a mitered corner.
Text: Represents the text that is drawn.
Position: The Position where the text element is drawn.