Pdf | |
The PdfTextElement type exposes the following members.
| Name | Description | |
|---|---|---|
| PdfTextElement(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. | |
| PdfTextElement(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). | |
| PdfTextElement(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. | |
| PdfTextElement(Single, Single, Single, Single, String, PdfFont) | Creates a text element at (x, y) with the specified width and height, text, and font. | |
| PdfTextElement(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). | |
| PdfTextElement(Single, Single, Single, Single, String, PdfFont, PdfColor) | Creates a text element at (x, y) with the specified width, height, text, font, and color. |
| Name | Description | |
|---|---|---|
| ActualText |
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) | |
| AlternateText |
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) | |
| Artifact |
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) | |
| BackColor |
Gets or sets the background fill color.
(Inherited from PdfElement) | |
| Blending |
Gets or sets the blending mode.
(Inherited from PdfElement) | |
| CharacterSpacing | Gets or sets an additional space between characters, in points. | |
| ClipRectangle | 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). | |
| ColorSpace |
Gets or sets the color space for the pdf element rendering.
(Inherited from PdfElement) | |
| Direction | 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. | |
| Font | Gets or sets the font used for rendering the text. | |
| ForeColor |
Gets or sets the foreground color used for drawing outlines and text.
(Inherited from PdfElement) | |
| Gradient |
Gets or sets the gradient fill. When set, overrides BackColor for fills.
(Inherited from PdfElement) | |
| Height | 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). | |
| HorizontalAlign | Gets or sets the horizontal text alignment. | |
| Layer |
Gets or sets the layer (optional content) the element is drawn in: shown and hidden with it in a viewer, printed
as the layer says. Null (default) draws it on the page itself, or in the layer of the template it is added to
(Layer). The layer must belong to the document the element is added to.
(Inherited from PdfPageElement) | |
| Leading | 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). | |
| LineStyle |
Gets or sets the line style for outline drawing.
(Inherited from PdfElement) | |
| RightToLeft | Gets or sets a value indicating whether the text is rendered right-to-left. | |
| Rotated |
Gets a value indicating whether a rotation has been applied.
(Inherited from PdfElement) | |
| Scaled |
Gets a value indicating whether a scale has been applied.
(Inherited from PdfElement) | |
| Skewed |
Gets a value indicating whether a skew has been applied.
(Inherited from PdfElement) | |
| TagType |
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) | |
| Text | Gets or sets the text string to render. | |
| TextRise | 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. | |
| Translated |
Gets a value indicating whether a translation has been applied.
(Inherited from PdfElement) | |
| Transparency |
Gets or sets the transparency level (0 = completely transparent, 100 = completely opaque).
(Inherited from PdfElement) | |
| VerticalAlign | Gets or sets the vertical text alignment. | |
| Width | 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). | |
| WordSpacing | Gets or sets an additional space between words, in points. Words are separated by the ASCII space character (code 32). | |
| X | Gets or sets the X coordinate where the text will be rendered. | |
| Y | Gets or sets the Y coordinate where the text will be rendered. |
| Name | Description | |
|---|---|---|
| Rotate |
Applies a rotation transformation.
(Inherited from PdfElement) | |
| Scale |
Applies a scale transformation.
(Inherited from PdfElement) | |
| Skew |
Applies a skew transformation.
(Inherited from PdfElement) | |
| Translate |
Applies a translation transformation.
(Inherited from PdfElement) |
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.
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();