Skip to main content

FormattedTextArea

Version: 12.0

FormattedTextArea

The FormattedTextArea class allows formatting within a paragraph of text using common and familiar HTML-style tagging. The FormattedTextArea is not designed to support full HTML tags but it will accept the following HTML tags and attributes. Some of the attributes are in addition to the attribute found in HTML and are used for advanced paragraph and line properties. Please note that white space can be treated literally or ignored (standard behavior for HTML).

important

This class is superseded by the HtmlArea class, which accepts HTML and CSS.

The FormattedTextAreaStyle class internally manages the state of the FormattedTextArea. The style property represents the initial state of the text.

tip

If working with complex HTML documents, then consider using either DynamicPDF HTML Converter for .NET or DynamicPDF Converter for .NET

Example​

The following example illustrates adding a FormattedTextArea to a PDF document.

Document document = new();
document.Pages.Add(new Page(PageSize.Letter));

string txt = File.ReadAllText("simple-fta.txt");
float pgWdth = doc.Pages[0].Dimensions.Width - document.Pages[0].Dimensions.LeftMargin * 2;

FormattedTextAreaStyle style = new(FontFamily.Helvetica, 12, false);
FormattedTextArea fta = new(txt, 0, 0, pgWdth, 0, style);
fta.Height = fta.GetRequiredHeight();
document.Pages[0].Elements.Add(fta);
document.Draw(outputPath);
Dim doc As New Document()
doc.Pages.Add(New Page(PageSize.Letter))
Dim txt As String = File.ReadAllText("simple-fta.txt")
Dim pgWdth As Single = doc.Pages(0).Dimensions.Width - doc.Pages(0).Dimensions.LeftMargin * 2
Dim style As New FormattedTextAreaStyle(FontFamily.Helvetica, 12, False)
Dim fta As New FormattedTextArea(txt, 0, 0, pgWdth, 0, style)
fta.Height = fta.GetRequiredHeight()
doc.Pages(0).Elements.Add(fta)
doc.Draw(outputPath)

[FormattedTextAreaExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/FormattedTextAreaExample.cs){#gitlink-id target=_blank}


[FormattedTextAreaExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/FormattedTextAreaExample.vb){#gitlink-id target=_blank}

Bold Tag​

<B.. tag - Enclosed text is bold.

Font Tag​

<Font ... tag - For font attributes.

AttributeValuesDescription
ColorWeb Color Hex String.Color of the text.
FaceA string value.The font family to use for the text. The 5 built-in font families ("Times" | "Helvetica" | "Courier" | "Symbol" |<br> "ZapfDingbats") can be specified or additional ones can be added through the HtmlTextArea's FontFaces property.
SizeAn integer value.Specifies the HTML font size for the text. This is mapped to a point size internally (0 = 6 points, 1 = 8 points, 2 = 10 points, 3 = 12 points, 4 = 14 points, 5 = 18 points, 6 = 24 points, 7 = 36 points).
PointSizeA decimal value.The size in points of the text.

Italics Tag​

<I ... tag - Enclosed text is italics.

Enclosed text is italic.

Line Tag​

<Line ... tag - Enclosed text is lined.

AttributeValuesDescription
LeadingA decimal value.The leading of the line.
LeadingTypeauto | atLeast | exactlySpecifies how leading is calculated.

Paragraph Tag​

AttributeValuesDescription
Alignleft | right | center | justifyAlignment of the paragraph's text.
AllowOrphanLinestrue | falseSpecifies if one orphaned line on a page has to be carried to the next page by itself or it will be carried along with the previous line to make it two lines on the next page.
IndentA decimal value.The first line indentation of the paragraph in points.
LeftIndentA decimal value.The left indentation of the paragraph in points.
PreserveWhiteSpacetrue | falseSpecifies if white space should be preserved.
RightIndentA decimal value.The right indentation of the paragraph in points.
SpacingAfterA decimal value.The spacing after the paragraph in points.
SpacingBeforeA decimal value.The spacing before the paragraph in points.

Subscript Tag​

<SUB ... tag - For subscript attributes.

AttributeValuesenscription
DisplacementA decimal value.The positive value will move the text downwards.

Superscript Tag​

<SUP ... tag - For superscript attributes.

AttributeValuesDescription
DisplacementA decimal value.The positive value will move the text upwards.

Underline Tag​

<U ... tag - Enclosed text is underlined.

Break Tag​

<BR ...tag - Inserts a single line break.