Skip to main content

TextArea

Version: 7.0

cete.dynamicpdf.pageelements.textarea

TextArea​

Represents an area of text.

public class TextArea : RotatingPageElement, IArea, ICoordinate, ISerializable
Public Class TextArea
Inherits RotatingPageElement
Implements IArea, ICoordinate, ISerializable

Inheritance: Object → PageElement → TaggablePageElement → RotatingPageElement → TextArea

Implements: IArea, ICoordinate, ISerializable

Licensing​

This class is a DynamicPDF Generator Professional Edition feature. One of the following licenses is required for non-evaluation usage:

  • DynamicPDF Generator for .NET Professional Edition
  • DynamicPDF Generator for .NET Enterprise Edition
  • DynamicPDF Merger for .NET Professional Edition
  • DynamicPDF Merger for .NET Enterprise Edition
  • DynamicPDF ReportWriter for .NET Professional Edition
  • DynamicPDF ReportWriter for .NET Enterprise Edition
  • DynamicPDF Core Suite for .NET Professional Edition
  • DynamicPDF Core Suite for .NET Enterprise Edition

Examples​

The following example will display text on the page.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements

Module MyModule
Sub Main()
' Create a PDF Document
Dim MyDocument As Document = New Document
' Create a Page and add it to the document
Dim MyPage As Page = New Page
MyDocument.Pages.Add(MyPage)

' Create a text area
Dim MyTextArea As TextArea = New TextArea("This is the " + "underlined text of a TextArea", 100, 100, 400, 30, _ ceTe.DynamicPDF.Font.HelveticaBoldOblique, 18)

' Change the underline property to true
MyTextArea.Underline = True

' Add the text to the page
MyPage.Elements.Add(MyTextArea)

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")
End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

class MyClass
{
static void Main()
{
// Create a PDF Document
Document document = new Document();

// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add( page );
// Create a text area
TextArea textArea = new TextArea( "This is the underlined " + "text of a TextArea", 100, 100, 400, 30, ceTe.DynamicPDF.Font.HelveticaBoldOblique, 18 );

// Change the underline property to true
textArea.Underline = true;

// Add the text area to the page
page.Elements.Add( textArea );

// Save the PDF
document.Draw( @"C:\MyDocument.pdf" );
}
}

Remarks​

This class can be used to place text on a page. Using the methods GetOverflowText or GetOverflowTextArea and HasOverflowText, users can control the pagination of TextAreas that come from a source of unknown length. See the Text Continuation topic for more on text continuation.

Constructors​

TextArea(String, Single, Single, Single, Single)​

Initializes a new instance of the TextArea class.

public TextArea(string text, float x, float y, float width, float height)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single)

Parameters​

Text to display in the text area.

X coordinate of the text area.

Y coordinate of the text area.

Width of the text area.

Height of the text area.

TextArea(String, Single, Single, Single, Single, Font)​

Initializes a new instance of the TextArea class.

public TextArea(string text, float x, float y, float width, float height, Font font)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single, font As Font)

Parameters​

Text to display in the text area.

X coordinate of the text area.

Y coordinate of the text area.

Width of the text area.

Height of the text area.

Font for the text of the text area.

TextArea(String, Single, Single, Single, Single, Font, Single)​

Initializes a new instance of the TextArea class.

public TextArea(string text, float x, float y, float width, float height, Font font, float fontSize)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single, font As Font, fontSize As Single)

Parameters​

Text to display in the text area.

X coordinate of the text area.

Y coordinate of the text area.

Width of the text area.

Height of the text area.

Font for the text of the text area.

Font size of the text of the text area.

TextArea(String, Single, Single, Single, Single, Font, Single, Color)​

Initializes a new instance of the TextArea class.

public TextArea(string text, float x, float y, float width, float height, Font font, float fontSize, Color textColor)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single, font As Font, fontSize As Single, textColor As Color)

Parameters​

Text to display in the text area.

X coordinate of the text area.

Y coordinate of the text area.

Width of the text area.

Height of the text area.

Font for the text of the text area.

Font size of the text of the text area.

Color of the text of the text area.

TextArea(String, Single, Single, Single, Single, Font, Single, TextAlign)​

Initializes a new instance of the TextArea class.

public TextArea(string text, float x, float y, float width, float height, Font font, float fontSize, TextAlign align)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single, font As Font, fontSize As Single, align As TextAlign)

Parameters​

Text to display in the text area.

X coordinate of the text area.

Y coordinate of the text area.

Width of the text area.

Height of the text area.

Font for the text of the text area.

Font size of the text of the text area.

Alignment of the text of the text area.

TextArea(String, Single, Single, Single, Single, Font, Single, TextAlign, Color)​

Initializes a new instance of the TextArea class.

public TextArea(string text, float x, float y, float width, float height, Font font, float fontSize, TextAlign align, Color textColor)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single, font As Font, fontSize As Single, align As TextAlign, textColor As Color)

Parameters​

Text to display in the text area.

X coordinate of the text area.

Y coordinate of the text area.

Width of the text area.

Height of the text area.

Font for the text of the text area.

Font size of the text of the text area.

Alignment of the text of the text area.

Color of the text of the text area.

Properties​

Align​

Gets or sets the TextAlign enumeration that specifies the text alignment of the text area.

public TextAlign Align { get; set; }
Public Property Align As TextAlign

Property Value​

TextAlign

Angle​

Gets or sets the heights of the angle element. (Inherited from RotatingPageElement)

public float Angle { get; set; }
Public Property Angle As Single

Property Value​

Single

AutoLeading​

Gets or sets a value indicating whether the leading of the text area should be calculated automatically.

public bool AutoLeading { get; set; }
Public Property AutoLeading As Boolean

Property Value​

Boolean

Remarks​

This property is automatically set to false any time the Leading property is set.

CleanParagraphBreaks​

Gets or sets the clean paragraph breaks for the paragraphs of the text area.

public bool CleanParagraphBreaks { get; set; }
Public Property CleanParagraphBreaks As Boolean

Property Value​

Boolean

Font​

Gets or sets the Font object used to specify the font of the text for the text area.

public Font Font { get; set; }
Public Property Font As Font

Property Value​

Font

FontSize​

Gets or sets the font size for the text of the text area.

public float FontSize { get; set; }
Public Property FontSize As Single

Property Value​

Single

Height​

Gets or sets the height of the text area.

public float Height { get; set; }
Public Property Height As Single

Property Value​

Single

ID​

Gets or sets the ID of the page element. (Inherited from PageElement)

public string ID { get; set; }
Public Property ID As String

Property Value​

String

KerningEnabled​

Enable or disable the kerning property of the text.

public bool KerningEnabled { get; set; }
Public Property KerningEnabled As Boolean

Property Value​

Boolean

Leading​

Gets or sets the leading for the text of the text area.

public float Leading { get; set; }
Public Property Leading As Single

Property Value​

Single

Remarks​

Setting this property will automatically set the AutoLeading property to false.

ParagraphIndent​

Gets or sets the paragraph indenting for the paragraphs of the text area.

public float ParagraphIndent { get; set; }
Public Property ParagraphIndent As Single

Property Value​

Single

ParagraphSpacing​

Gets or sets the paragraph spacing for the paragraphs of the text area.

public float ParagraphSpacing { get; set; }
Public Property ParagraphSpacing As Single

Property Value​

Single

RightToLeft​

Gets or sets a value indicating if text should be displayed right to left.

public bool RightToLeft { get; set; }
Public Property RightToLeft As Boolean

Property Value​

Boolean

Tag​

Gets or sets the tag of the taggable element. (Inherited from TaggablePageElement)

public Tag Tag { get; set; }
Public Property Tag As Tag

Property Value​

Tag

Licensing​

This property is a DynamicPDF Generator Enterprise Edition feature. One of the following licenses is required for non-evaluation usage:

  • DynamicPDF Generator for .NET Enterprise Edition
  • DynamicPDF Merger for .NET Enterprise Edition
  • DynamicPDF ReportWriter for .NET Enterprise Edition
  • DynamicPDF Core Suite for .NET Enterprise Edition

TagOrder​

Gets or sets the tag order of the taggable element. (Inherited from TaggablePageElement)

public int TagOrder { get; set; }
Public Property TagOrder As Int32

Property Value​

Int32

Text​

Gets or sets the text of the text area.

public string Text { get; set; }
Public Property Text As String

Property Value​

String

TextColor​

Gets or sets the Color object to use for the text of the text area.

public Color TextColor { get; set; }
Public Property TextColor As Color

Property Value​

Color

Underline​

Gets or sets a value indicating if the text area is underlined.

public bool Underline { get; set; }
Public Property Underline As Boolean

Property Value​

Boolean

VAlign​

Gets or sets the VAlign enumeration that specifies the vertical text alignment of the text area.

public VAlign VAlign { get; set; }
Public Property VAlign As VAlign

Property Value​

VAlign

Width​

Gets or sets the width of the text area.

public float Width { get; set; }
Public Property Width As Single

Property Value​

Single

X​

Gets or sets the X coordinate of the page element. (Inherited from RotatingPageElement)

public float X { get; set; }
Public Property X As Single

Property Value​

Single

Y​

Gets or sets the Y coordinate of the page element. (Inherited from RotatingPageElement)

public float Y { get; set; }
Public Property Y As Single

Property Value​

Single

Methods​

Draw(PageWriter)​

Draws the page element to the given PageWriter object. (Inherited from RotatingPageElement)

public void Draw(PageWriter writer)
Sub Draw(writer As PageWriter)

Parameters​

PageWriter object to receive the page element's output.

Equals(Object)​

Determines whether the specified Object is equal to the current Object . (Inherited from Object)

public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean

Parameters​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

GetHashCode()​

Serves as a hash function for a particular type. (Inherited from Object)

public int GetHashCode()
Function GetHashCode() As Integer

Returns​

A hash code for the current Object .

GetKerningValues()​

Gets the Kerning values.

public KerningValues GetKerningValues()
Function GetKerningValues() As KerningValues

Returns​

KerningValues The kerning values.

Exceptions​

If KerningEnabled is set to false.

Examples​

The following exmaple demonstrates how to apply custom kerning.

Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.Text
Imports ceTe.DynamicPDF.PageElements

Module Module1

Sub Main()

' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a PDF Page
Dim MyPage As Page = New Page

' Create a Texr Area
Dim MyTextArea As TextArea = New TextArea("Text with kerning", 10, 10, 200, 100)

' Enable the kerning for the text area
MyTextArea.KerningEnabled = True

' Get the Kerning Pairs for the text area
Dim MyKerningValues As KerningValues = MyTextArea.GetKerningValues

' Apply a custom kerning value between 'T' & 'e' in 'Text'
' so that chars will be closer than normal
MyKerningValues.Spacing(0) = 200

' Add the text area to the page
MyPage.Elements.Add(MyTextArea)

' Add the page to the document
MyDocument.Pages.Add(MyPage)

' Save the document
MyDocument.Draw("C:\MyDocument.pdf")

End Sub

End Module

using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.Text;
using ceTe.DynamicPDF.PageElements;

class MyClass
{
static void Main(string[] args)
{
// Create a PDF Document
Document document = new Document();

// Create a PDF Page
Page page = new Page();

// Create a Texr Area
TextArea textArea = new TextArea("Text with kerning", 10, 10, 200, 100);

// Enable the kerning for the text area
textArea.KerningEnabled = true;

// Get the Kerning Pairs for the text area
KerningValues kerningValues = textArea.GetKerningValues();

// Apply a custom kerning value between 'T' & 'e' in 'Text'
// so that chars will be closer than normal
kerningValues.Spacing[0] = 200;

// Add the text area to the page
page.Elements.Add(textArea);

// Add the page to the document
document.Pages.Add(page);

// Save the document
document.Draw(@"C:\MyDocument.pdf");
}
}

GetLineTextWidth(Int32)​

Returns the width of the given line index with kerning spaces.

public float GetLineTextWidth(int lineIndex)
Function GetLineTextWidth(lineIndex As Integer) As Single

Parameters​

Line number of the textarea.

Returns​

Width of the line with kerning spaces.

GetOverflowText()​

Returns the text remaining that will be clipped by the text area.

public string GetOverflowText()
Function GetOverflowText() As String

Returns​

The overflow text as a string .

GetOverflowTextArea()​

Returns a TextArea object containing the overflow text.

public TextArea GetOverflowTextArea()
Function GetOverflowTextArea() As TextArea

Returns​

Returns a TextArea object.

Examples​

The following example shows you how to use the GetOverflowTextArea object to allow text of variable length to flow onto new pages as needed.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements

Module MyModule
Sub Main()
' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a string and assign it to text of variable length
Dim myVariableText As String = ""
Dim i As Integer
For i = 0 To 50
myVariableText &= "This is a sentence that I will use as my variable length text. "
Next
' Create a text area
Dim MyTextArea As TextArea = New TextArea(myVariableText, 0, 0, 250, 200)
Do
' Create a new page
Dim MyPage As Page = New Page

' Add the text area to the page;
MyPage.Elements.Add(MyTextArea)

' Add the page to the document
MyDocument.Pages.Add(MyPage)

' Set the text area object equal to the rest of the text that did not fit
' if all the text fit this will set textArea to null
MyTextArea = MyTextArea.GetOverflowTextArea()
Loop While Not MyTextArea Is Nothing

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")
End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

class MyClass
{
static void Main()
{
// Create a PDF Document
Document document = new Document();

// Create a string and assign it to text of variable length
string variableText = "";
for( int i = 0; i < 50; i++ )
variableText += "This is a sentence that I will use as my variable length text. ";

// Create a text area
TextArea textArea = new TextArea( variableText, 0, 0, 250, 200 );
do
{
// Create a new page
Page page = new Page();

// Add the text area to the page;
page.Elements.Add( textArea );

// Add the page to the document
document.Pages.Add( page );

// Set the text area object equal to the rest of the text that did not fit
// if all the text did fit, GetOverflowTextArea will return null
textArea = textArea.GetOverflowTextArea();
} while( textArea != null );
// Save the PDF
document.Draw( @"C:\MyDocument.pdf" );
}
}

Remarks​

This method returns a new TextArea object that contains the remaining text that did not fit.

GetOverflowTextArea(Single, Single)​

Returns a TextArea object containing the overflow text.

public TextArea GetOverflowTextArea(float x, float y)
Function GetOverflowTextArea(x As Single, y As Single) As TextArea

Parameters​

X coordinate of the new text area.

Y coordinate of the new text area.

Returns​

Returns a TextArea object.

Examples​

The following example shows you how to use the GetOverflowTextArea object to allow text of variable length to flow onto new pages as needed.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements

Module MyModule
Sub Main()
' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a string and assign it to text of variable length
Dim myVariableText As String = ""
Dim i As Integer
For i = 0 To 50
myVariableText &= "This is a sentence that I will use as my variable length text. "
Next
' Create a text area
Dim MyTextArea As TextArea = New TextArea(myVariableText, 0, 0, 250, 200)
Do
' Create a new page
Dim MyPage As Page = New Page

' Add the text area to the page;
MyPage.Elements.Add(MyTextArea)

' Add the page to the document
MyDocument.Pages.Add(MyPage)

' Set the text area object equal to the rest of the text that did not fit
' if all the text fit this will set textArea to null
MyTextArea = MyTextArea.GetOverflowTextArea(50, 50)
Loop While Not MyTextArea Is Nothing

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")
End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

class MyClass
{
static void Main()
{
// Create a PDF Document
Document document = new Document();

// Create a string and assign it to text of variable length
string variableText = "";
for( int i = 0; i < 50; i++ )
variableText += "This is a sentence that I will use as my variable length text. ";

// Create a text area
TextArea textArea = new TextArea( variableText, 0, 0, 250, 200 );
do
{
// Create a new page
Page page = new Page();

// Add the text area to the page;
page.Elements.Add( textArea );

// Add the page to the document
document.Pages.Add( page );

// Set the text area object equal to the rest of the text that did not fit
// if all the text did fit, GetOverflowTextArea will return null
textArea = textArea.GetOverflowTextArea( 50, 50 );
} while( textArea != null );
// Save the PDF
document.Draw( @"C:\MyDocument.pdf" );
}
}

Remarks​

This method returns a new TextArea object that contains the remaining text that did not fit.

GetOverflowTextArea(Single, Single, Single, Single)​

Returns a TextArea object containing the overflow text.

public TextArea GetOverflowTextArea(float x, float y, float width, float height)
Function GetOverflowTextArea(x As Single, y As Single, width As Single, height As Single) As TextArea

Parameters​

X coordinate of the new text area.

Y coordinate of the new text area.

Width of the new text area.

Height of the new text area.

Returns​

Returns a TextArea object.

Examples​

The following example shows you how to use the GetOverflowTextArea object to allow text of variable length to flow onto new pages as needed.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements

Module MyModule
Sub Main()
' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a string and assign it to text of variable length
Dim myVariableText As String = ""
Dim i As Integer
For i = 0 To 50
myVariableText &= "This is a sentence that I will use as my variable length text. "
Next
' Create a text area
Dim MyTextArea As TextArea = New TextArea(myVariableText, 0, 0, 250, 200)
Do
' Create a new page
Dim MyPage As Page = New Page

' Add the text area to the page;
MyPage.Elements.Add(MyTextArea)

' Add the page to the document
MyDocument.Pages.Add(MyPage)

' Set the text area object equal to the rest of the text that did not fit
' if all the text fit this will set textArea to null
MyTextArea = MyTextArea.GetOverflowTextArea(50, 50, 100,200)
Loop While Not MyTextArea Is Nothing

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")
End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

class MyClass
{
static void Main()
{
// Create a PDF Document
Document document = new Document();

// Create a string and assign it to text of variable length
string variableText = "";
for( int i = 0; i < 50; i++ )
variableText += "This is a sentence that I will use as my variable length text. ";

// Create a text area
TextArea textArea = new TextArea( variableText, 0, 0, 250, 200 );
do
{
// Create a new page
Page page = new Page();

// Add the text area to the page;
page.Elements.Add( textArea );

// Add the page to the document
document.Pages.Add( page );

// Set the text area object equal to the rest of the text that did not fit
// if all the text did fit, GetOverflowTextArea will return null
textArea = textArea.GetOverflowTextArea( 50, 50, 100,200);
} while( textArea != null );
// Save the PDF
document.Draw( @"C:\MyDocument.pdf" );
}
}

Remarks​

This method returns a new TextArea object that contains the remaining text that did not fit.

GetRequiredHeight()​

Returns the height required to fit all of the text supplied.

public float GetRequiredHeight()
Function GetRequiredHeight() As Single

Returns​

The required height to display all text.

GetTextHeight()​

Returns the height of the text that will be drawn.

public float GetTextHeight()
Function GetTextHeight() As Single

Returns​

The height of visible text.

GetType()​

Gets the Type of the current instance. (Inherited from Object)

public Type GetType()
Function GetType() As Type

Returns​

The Type instance that represents the exact runtime type of the current instance.

GetVisibleLineCount()​

Returns the number of lines that will be displayed in the current textarea.

public int GetVisibleLineCount()
Function GetVisibleLineCount() As Integer

Returns​

The number are lines that will display.

HasOverflowText()​

Returns a value indicating if there is text remaining that will not be drawn to the text area.

public bool HasOverflowText()
Function HasOverflowText() As Boolean

Returns​

Value indication whether or not overflow text exists.

ToString()​

Returns a String that represents the current Object . (Inherited from Object)

public string ToString()
Function ToString() As String

Returns​

A String that represents the current Object .

See Also​

ceTe.DynamicPDF.PageElements