Click or drag to resize
Pdf Library for .NET

PdfTextElement Class

Represents a text that can be added to a pdf document. The text element supports pagination — when the rendered text does not fit on the current page, additional pages are created automatically to hold the remaining content.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalPdfPageElement
    SelectPdf.UniversalPdfElement
      SelectPdf.UniversalPdfTextElement

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.4
Syntax
public class PdfTextElement : PdfElement

The PdfTextElement type exposes the following members.

Constructors
 NameDescription
Public methodPdfTextElement(Single, Single, String, PdfFont) Creates a text element at (x, y) with the specified text and font. The height is auto-determined and the width is the available page width.
Public methodPdfTextElement(Single, Single, Single, String, PdfFont) Creates a text element at (x, y) with the specified width, text, and font. The height is auto-determined (content paginates across pages if needed).
Public methodPdfTextElement(Single, Single, String, PdfFont, PdfColor) Creates a text element at (x, y) with the specified text, font, and color. The height is auto-determined and the width is the available page width.
Public methodPdfTextElement(Single, Single, Single, Single, String, PdfFont) Creates a text element at (x, y) with the specified width and height, text, and font.
Public methodPdfTextElement(Single, Single, Single, String, PdfFont, PdfColor) Creates a text element at (x, y) with the specified width, text, font, and color. The height is auto-determined (content paginates across pages if needed).
Public methodPdfTextElement(Single, Single, Single, Single, String, PdfFont, PdfColor) Creates a text element at (x, y) with the specified width, height, text, font, and color.
Top
Properties
 NameDescription
Public propertyActualText Gets or sets the exact text represented by this element (the structure element's /ActualText entry), used when the drawn glyphs do not map to readable text.
(Inherited from PdfPageElement)
Public propertyAlternateText Gets or sets the alternate text describing this element for assistive technology (the structure element's /Alt entry). Required on figures for PDF/UA conformance.
(Inherited from PdfPageElement)
Public propertyArtifact Gets or sets a value indicating whether this element is an artifact — decorative or layout content that carries no meaning and is excluded from the logical structure (backgrounds, rules, running headers). Takes precedence over TagType.
(Inherited from PdfPageElement)
Public propertyBackColor Gets or sets the background fill color.
(Inherited from PdfElement)
Public propertyBlending Gets or sets the blending mode.
(Inherited from PdfElement)
Public propertyCharacterSpacing Gets or sets an additional space between characters, in points.
Public propertyClipRectangle Gets or sets a rectangle to be added to the current clipping path. Text outside this rectangle is clipped at render time. Use Empty to disable clipping (the default).
Public propertyColorSpace Gets or sets the color space for the pdf element rendering.
(Inherited from PdfElement)
Public propertyDirection Gets or sets a rotation angle, in degrees, applied counter-clockwise around the starting point (X, Y). The default value of 0 means no rotation.
Public propertyFont Gets or sets the font used for rendering the text.
Public propertyForeColor Gets or sets the foreground color used for drawing outlines and text.
(Inherited from PdfElement)
Public propertyGradient Gets or sets the gradient fill. When set, overrides BackColor for fills.
(Inherited from PdfElement)
Public propertyHeight Gets or sets the height of the text layout rectangle. A value of -1 means auto (unbounded — the text will paginate to additional pages if it does not fit).
Public propertyHorizontalAlign Gets or sets the horizontal text alignment.
Public propertyLeading Gets or sets the vertical distance between the baselines of adjacent lines of text. A value of -1 means "use the font default" (the common case).
Public propertyLineStyle Gets or sets the line style for outline drawing.
(Inherited from PdfElement)
Public propertyRightToLeft Gets or sets a value indicating whether the text is rendered right-to-left.
Public propertyRotated Gets a value indicating whether a rotation has been applied.
(Inherited from PdfElement)
Public propertyScaled Gets a value indicating whether a scale has been applied.
(Inherited from PdfElement)
Public propertySkewed Gets a value indicating whether a skew has been applied.
(Inherited from PdfElement)
Public propertyTagType Gets or sets the structure type used to tag this element in a tagged (accessible) document. Ignored unless the document's tagged mode (PdfDocument.Tagged) is enabled. Null (default) leaves the element untagged unless Artifact is set.
(Inherited from PdfPageElement)
Public propertyText Gets or sets the text string to render.
Public propertyTextRise Gets or sets the distance, in points, to move the text baseline up (positive) or down (negative) from its default location. Positive values create a superscript-like effect; negative values create a subscript-like effect. The default, -1, is a sentinel meaning "no baseline offset"; assign any other value, including 0, to set an explicit rise.
Public propertyTranslated Gets a value indicating whether a translation has been applied.
(Inherited from PdfElement)
Public propertyTransparency Gets or sets the transparency level (0 = completely transparent, 100 = completely opaque).
(Inherited from PdfElement)
Public propertyVerticalAlign Gets or sets the vertical text alignment.
Public propertyWidth Gets or sets the width of the text layout rectangle. A value of -1 means auto (use the available page width from X to the right edge).
Public propertyWordSpacing Gets or sets an additional space between words, in points. Words are separated by the ASCII space character (code 32).
Public propertyX Gets or sets the X coordinate where the text will be rendered.
Public propertyY Gets or sets the Y coordinate where the text will be rendered.
Top
Methods
 NameDescription
Public methodRotate Applies a rotation transformation.
(Inherited from PdfElement)
Public methodScale Applies a scale transformation.
(Inherited from PdfElement)
Public methodSkew Applies a skew transformation.
(Inherited from PdfElement)
Public methodTranslate Applies a translation transformation.
(Inherited from PdfElement)
Top
Remarks

Coordinates (X, Y) and Width / Height are expressed in the page's client-area coordinate system — that is, relative to the top-left corner of the page area inside the margins. On a page with Margins = 40, passing X = 0 places the text flush against the left margin (absolute MediaBox x = 40), and Width = ClientSize.Width fills the entire writable area without entering the right margin.

Common mistake: on a page with 40pt margins, calling new PdfTextElement(40, 40, 515, text, font) adds another 40pt to the left and right, so the rect ends at MediaBox x=595 (the page edge) — the rightmost portion renders into the right margin strip and appears "cut" in viewers whose window is narrower than the page. Use X = 0 and Width ≤ ClientSize.Width to keep text inside the margins.

Example
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
PdfFont font = PdfFont.CreateStandardFont(PdfStandardFont.Helvetica, 12);
PdfTextElement text =
    new PdfTextElement(0, 0, "Hello, world!", font, new PdfColor(0, 0, 0));
text.HorizontalAlign = PdfTextHorizontalAlign.Center;
page.Add(text);
document.Save("out.pdf");
document.Close();
See Also