Class TextLine
Line of text made up of one or more spans (PyMuPDF-style line).
Inheritance
Namespace: IronSoftware
Assembly: IronPdf.dll
Syntax
public class TextLine : Object
Extracting structured text from a PDF page becomes precise when each horizontal run of characters is captured as a TextLine, a record that groups one or more TextSpan objects sharing the same baseline into a single addressable unit. TextLine follows the PyMuPDF-style line model, making its layout familiar to developers who have worked with that ecosystem.
Four read-only properties expose everything needed for text analysis and coordinate-based processing. Contents returns the full plain-text string of the line, assembled from all its spans. BoundingBox gives the line's position and size as a RectangleF, enabling pixel-accurate region comparisons, redaction targeting, or table-cell alignment checks. Index identifies the line's ordinal position within its parent block, so lines can be sorted or filtered by reading order. Spans provides an IReadOnlyList<TextSpan> of the individual styled segments that make up the line; iterating Spans lets you inspect font, size, or color variations within a single line without splitting the raw string manually.
A typical workflow retrieves TextLine objects from IronPDF's text extraction pipeline and then queries Contents for keyword matching or passes BoundingBox to a coordinate-aware extraction call.
using IronPdf;
foreach (TextLine line in pdfPage.TextLines)
{
if (line.Contents.Contains("Invoice", StringComparison.OrdinalIgnoreCase))
Console.WriteLine($"Line {line.Index} at Y={line.BoundingBox.Y}: {line.Contents}");
}The extract text from PDF how-to covers the full extraction pipeline, and the PDF text extraction examples show coordinate-based and span-level techniques.
Constructors
TextLine()
Declaration
public TextLine()
Properties
BoundingBox
Bounds in PDF user space, matching BoundingBox: Y grows upward, so Height is negative and Bottom sits below Top. Note that System.Drawing.RectangleF.IsEmpty is therefore true for a valid box.
Declaration
public RectangleF BoundingBox { get; }
Property Value
| Type | Description |
|---|---|
| System.Drawing.RectangleF |
Contents
Text of all spans in this line, joined without a separator.
Declaration
public string Contents { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Index
Zero based index of this line on the page, not within its parent block.
Declaration
public int Index { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Spans
Spans in this line, left to right.
Declaration
public IReadOnlyList<TextSpan> Spans { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IReadOnlyList<TextSpan> |