Class RepText
Represents a text object for a formatted single or multiline text in a PDF report, where the dimensions are in points.
public class RepText : FlowContainer
- Inheritance
-
RepText
- Derived
- Inherited Members
Examples
StandardFontDef fontDef = new(StandardFont.Helvetica);
FontProp font = new(fontDef, 10);
new RepText(font, $"The {RepText.BoldOn}area{RepText.BoldOff} is 2000 m{RepText.Superscript("2")} in size.", 100);
Result: The area is 2000 m2 in size.
Constructors
RepText(FontProp, string, TextOptions)
Initializes a new instance of the RepText class with the specified font, text and text options.
public RepText(FontProp font, string text, TextOptions options = TextOptions.None)
Parameters
font
FontPropThe font for the string.
text
stringThe text.
options
TextOptionsThe text options for the text.
Remarks
The text is automatically wrapped into lines if it is too long.
A line break is forced by \n
.
Automatic wrapping occurs at spaces or hyphens if there is a letter before and after.
If a word no longer fits on the line, it is written on the next line.
An automatic line break removes all spaces between the two words where the line break occurs.
If a word is wider than the text box and cannot be separated regularly, it is wrapped as best as possible within the word.
If a letter is wider than the text box, the letter is displayed in one line and determines the width of the text box.
Spaces at the beginning of a new line cause the text to be indented by the spaces.
Spaces at the end of the text are displayed up to the end of the line.
There are two ways to format text: escape sequences and HTML tags (see TextOptions.Html).
Character / Excape Sequence | HTML Tags | Description |
---|---|---|
\r | - | will be ignored |
\n | - | new line |
All other characters in the range of 0..31 | - | cannot be used and will throw an exception |
BoldOn, BoldOff, Bold(string) | <b> </b> | Sets the font style to bold . |
ItalicOn, ItalicOff, Italic(string) | <i> </i> | Sets the font style to italic . |
UnderlineOn, UnderlineOff, Underline(string) | <u> </u> | Sets the font style to underline . |
StrikethroughOn, StrikethroughOff, Strikethrough(string) | <s> </s> | Sets the font style to strikethrough . |
SubscriptOn, SubscriptOff, Subscript(string) | <sub> </sub> | Sets the font style to subscript . |
SuperscriptOn, SuperscriptOff, Superscript(string) | <sup> </sup> | Sets the font style to superscript . |
FontSize(double), FontSizeMM(double) | - | Sets the font size. |
FontColor(Color) | - | Sets the font color. |
BackgroundOn, BackgroundOff, Background(Color) | <mark> </mark> | Sets the background used to highlight text. |
Supported text options:
TextOption | Description |
---|---|
None | No special formatting. |
Center | Each line of text is centered. |
Right | Each line of text is right-aligned. |
AdjustWidth | The width of the bounding box is set to the longest line of text. |
Html | The text contains HTML formatting. |
A text object can be splitted on multiple pages, see class VerticalObjectSplitter and example Flow Text Report.
Exceptions
- ArgumentNullException
The font or text is null.
RepText(FontProp, string, double, TextOptions)
Initializes a new instance of the RepText class with the specified font, text, maximum width in points and text options.
public RepText(FontProp font, string text, double width, TextOptions options = TextOptions.AdjustWidth)
Parameters
font
FontPropThe font for the string.
text
stringThe text.
width
doubleThe maximum width of a line in points.
options
TextOptionsThe text options for the text.
Remarks
The text is automatically wrapped into lines if it is too long.
A line break is forced by \n
.
Automatic wrapping occurs at spaces or hyphens if there is a letter before and after.
If a word no longer fits on the line, it is written on the next line.
An automatic line break removes all spaces between the two words where the line break occurs.
If a word is wider than the text box and cannot be separated regularly, it is wrapped as best as possible within the word.
If a letter is wider than the text box, the letter is displayed in one line and determines the width of the text box.
Spaces at the beginning of a new line cause the text to be indented by the spaces.
Spaces at the end of the text are displayed up to the end of the line.
There are two ways to format text: escape sequences and HTML tags (see TextOptions.Html).
Character / Excape Sequence | HTML Tags | Description |
---|---|---|
\r | - | will be ignored |
\n | - | new line |
All other characters in the range of 0..31 | - | cannot be used and will throw an exception |
BoldOn, BoldOff, Bold(string) | <b> </b> | Sets the font style to bold . |
ItalicOn, ItalicOff, Italic(string) | <i> </i> | Sets the font style to italic . |
UnderlineOn, UnderlineOff, Underline(string) | <u> </u> | Sets the font style to underline . |
StrikethroughOn, StrikethroughOff, Strikethrough(string) | <s> </s> | Sets the font style to strikethrough . |
SubscriptOn, SubscriptOff, Subscript(string) | <sub> </sub> | Sets the font style to subscript . |
SuperscriptOn, SuperscriptOff, Superscript(string) | <sup> </sup> | Sets the font style to superscript . |
FontSize(double), FontSizeMM(double) | - | Sets the font size. |
FontColor(Color) | - | Sets the font color. |
BackgroundOn, BackgroundOff, Background(Color) | <mark> </mark> | Sets the background used to highlight text. |
Supported text options:
TextOption | Description |
---|---|
None | No special formatting. |
Center | Each line of text is centered. |
Right | Each line of text is right-aligned. |
AdjustWidth | The width of the bounding box is set to the longest line of text. |
Html | The text contains HTML formatting. |
A text object can be splitted on multiple pages, see class VerticalObjectSplitter and example Flow Text Report.
Exceptions
- ArgumentNullException
The font or text is null.
- ArgumentOutOfRangeException
The width is less than or equal to zero.
- ArgumentException
Invalid option:
TruncateIfTooLong
,EllipsisIfTooLong
,SmallerFontIfToolLong
orCenter
together withRight
are not allowed.
Fields
BackgroundOff
Removes the background.
public const string BackgroundOff = "\u001bbg"
Field Value
- string
The escape sequence to turn off the background.
Examples
$"abc {RepText.BackgroundOn}def{RepText.BackgroundOff} ghi"
Result: abc def ghi
BackgroundOn
Sets the background used to highlight text. The default color is yellow
.
public const string BackgroundOn = "\u001bBG"
Field Value
- string
The escape sequence to mark the text.
Examples
$"abc {RepText.BackgroundOn}def{RepText.BackgroundOff} ghi"
Result: abc def ghi
BoldOff
Resets the font style to bold
.
public const string BoldOff = "\u001bbo"
Field Value
- string
The escape sequence to turn off the bold font.
Examples
$"abc {RepText.BoldOn}def{RepText.BoldOff} ghi"
Result: abc def ghi
BoldOn
Sets the font style to bold
.
public const string BoldOn = "\u001bBO"
Field Value
- string
The escape sequence to set the font to bold.
Examples
$"abc {RepText.BoldOn}def{RepText.BoldOff} ghi"
Result: abc def ghi
ItalicOff
Resets the font style to italic
.
public const string ItalicOff = "\u001bit"
Field Value
- string
The escape sequence to turn off the italic font.
Examples
$"abc {RepText.ItalicOn}def{RepText.ItalicOff} ghi"
Result: abc def ghi
ItalicOn
Sets the font style to italic
.
public const string ItalicOn = "\u001bIT"
Field Value
- string
The escape sequence to set the font to italic.
Examples
$"abc {RepText.ItalicOn}def{RepText.ItalicOff} ghi"
Result: abc def ghi
StrikethroughOff
Resets the font style to strikethrough
.
public const string StrikethroughOff = "\u001bst"
Field Value
- string
The escape sequence to turn off the strikethrough font.
Examples
$"abc {RepText.StrikethroughOn}def{RepText.StrikethroughOff} ghi"
Result: abc def ghi
StrikethroughOn
Sets the font style to strikethrough
.
public const string StrikethroughOn = "\u001bST"
Field Value
- string
The escape sequence for the strikethrough font.
Examples
$"abc {RepText.StrikethroughOn}def{RepText.StrikethroughOff} ghi"
Result: abc def ghi
SubscriptOff
Resets the font style subscript
.
public const string SubscriptOff = "\u001bsb"
Field Value
- string
The escape sequence to turn off the subscript font.
Examples
$"abc {RepText.SubscriptOn}def{RepText.SubscriptOff} ghi"
Result: abc def ghi
SubscriptOn
Sets the font style to subscript
.
public const string SubscriptOn = "\u001bSB"
Field Value
- string
The escape sequence for the subscript font.
Examples
$"abc {RepText.SubscriptOn}def{RepText.SubscriptOff} ghi"
Result: abc def ghi
SuperscriptOff
Resets the font style superscript
.
public const string SuperscriptOff = "\u001bsp"
Field Value
- string
The escape sequence to turn off the superscript font.
Examples
$"abc {RepText.SuperscriptOn}def{RepText.SuperscriptOff} ghi"
Result: abc def ghi
SuperscriptOn
Sets the font style to superscript
.
public const string SuperscriptOn = "\u001bSP"
Field Value
- string
The escape sequence for the superscript font.
Examples
$"abc {RepText.SuperscriptOn}def{RepText.SuperscriptOff} ghi"
Result: abc def ghi
UnderlineOff
Resets the font style to underline
.
public const string UnderlineOff = "\u001bul"
Field Value
- string
The escape sequence to turn off the underline font.
Examples
$"abc {RepText.UnderlineOn}def{RepText.UnderlineOff} ghi"
Result: abc def ghi
UnderlineOn
Sets the font style to underline
.
public const string UnderlineOn = "\u001bUL"
Field Value
- string
The escape sequence to underline the text.
Examples
$"abc {RepText.UnderlineOn}def{RepText.UnderlineOff} ghi"
Result: abc def ghi
Properties
Font
Gets the font properties for the text.
public FontProp Font { get; }
Property Value
- FontProp
The font properties.
Options
Gets the text options for the text object.
public TextOptions Options { get; }
Property Value
- TextOptions
The text options.
Text
Gets the text.
public string Text { get; }
Property Value
- string
The text.
Methods
Background(Color)
Sets the background to the specified color. The background color remains saved and can be used again with BackgroundOn.
public static string Background(Color color)
Parameters
color
ColorThe background color.
Returns
Examples
$"abc {RepText.Background(Color.Red)}def{RepText.BackgroundOff} ghi {RepText.BackgroundOn}jkl
Result: abc def ghi jkl
Bold(string)
Displays the specified text in bold
.
public static string Bold(string text)
Parameters
text
stringThe text.
Returns
- string
The escape sequence to make the text bold.
Examples
"abc " + RepText.Bold("def") + " ghi"
Result: abc def ghi
FontColor(Color)
Sets the font color.
public static string FontColor(Color color)
Parameters
color
ColorThe font color.
Returns
Examples
$"abc {RepText.FontColor(Color.Red)}def"
Result: abc def
FontSize(double)
Sets the font size.
public static string FontSize(double size)
Parameters
size
doubleThe font size in points.
Returns
Examples
$"abc {RepText.FontSize(14)}def"
Result: abc def
FontSizeMM(double)
Sets the font size.
public static string FontSizeMM(double sizeMM)
Parameters
sizeMM
doubleThe font size in millimeters.
Returns
Examples
$"abc {RepText.FontSizeMM(4.5)}def"
Result: abc def
Italic(string)
Displays the specified text in italic
.
public static string Italic(string text)
Parameters
text
stringThe text.
Returns
- string
The escape sequence to make the text italic.
Examples
"abc " + RepText.Italic("def") + " ghi"
Result: abc def ghi
Strikethrough(string)
Sets the font style to strikethrough
for the specified text.
public static string Strikethrough(string text)
Parameters
text
stringThe text.
Returns
Examples
"abc " + RepText.Strikethrough("def") + " ghi"
Result: abc def ghi
Subscript(string)
Sets the font style subscript
for the specified text.
public static string Subscript(string text)
Parameters
text
stringThe text.
Returns
Examples
"abc " + RepText.Subscript("def") + " ghi"
Result: abc def ghi
Superscript(string)
Sets the font style superscript
for the specified text.
public static string Superscript(string text)
Parameters
text
stringThe text.
Returns
Examples
"abc " + RepText.Superscript("def") + " ghi"
Result: abc def ghi
Underline(string)
Sets the font style to underline
for the specified text.
public static string Underline(string text)
Parameters
text
stringThe text.
Returns
- string
The escape sequence to underline the text.
Examples
"abc " + RepText.Underline("def") + " ghi"
Result: abc def ghi