Class TextSpan
Run of text sharing font, size and color (PyMuPDF-style span).
Inheritance
Namespace: IronSoftware
Assembly: IronPdf.dll
Syntax
public class TextSpan : Object
A TextSpan is the atomic record of extracted PDF text: a contiguous run of characters that share the same font, size, and fill color, modeled after the span concept in PyMuPDF. Whenever IronPDF walks a PDF page to surface its textual content, each visually uniform segment arrives as one of these objects, giving you precise access to both the characters and the typographic context around them.
The Contents property holds the raw string for the span. Alongside it, FontSize gives the point size, Font exposes the full FontObject descriptor (name, weight, and encoding details), and FillColor returns the rendered Color so you can distinguish, for example, red headings from black body text. BoundingBox provides a RectangleF in PDF user-space coordinates, which maps the span's position and dimensions onto the page, useful for spatial filtering or overlay annotation. When a span is composed of multiple discrete drawing operations, Fragments exposes each constituent TextObject as an IReadOnlyList<TextObject>, letting you inspect sub-span detail without losing the grouped view.
You do not construct TextSpan directly in typical workflows. Instances surface through IronPDF's text-extraction pipeline when you interrogate a PdfDocument page. From there, iterate the spans, filter by FillColor or FontSize, and read Contents to assemble the text you need.
using IronPdf;
using IronSoftware;
using var pdf = PdfDocument.FromFile("report.pdf");
var page = pdf.Pages[0];
foreach (TextSpan span in page.GetTextSpans())
{
if (span.FontSize >= 14f)
Console.WriteLine($"{span.Contents} [{span.BoundingBox.X:F1}, {span.BoundingBox.Y:F1}]");
}Because BoundingBox uses PDF user-space (origin at the bottom-left of the page), coordinates increase upward. Convert to screen coordinates by subtracting the Y value from the page height when you need top-left-origin positioning for overlays or crop operations.
Explore related topics in the IronPDF documentation: the text extraction how-to explains the full pipeline, the PDF reading examples show common patterns, the font handling guide covers FontObject usage, and the get started page walks through installation and licensing.
Constructors
TextSpan()
Declaration
public TextSpan()
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 this span.
Declaration
public string Contents { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
FillColor
Fill color of this span.
Declaration
public Color FillColor { get; }
Property Value
| Type | Description |
|---|---|
| System.Drawing.Color |
Font
Font of this span.
Declaration
public FontObject Font { get; }
Property Value
| Type | Description |
|---|---|
| FontObject |
FontSize
Font size in points as rendered on the page. See EffectiveFontSize.
Declaration
public float FontSize { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Fragments
Text fragments that make up this span, left to right.
These are the page's live text objects. Setting a property on one edits the document (not supported over a remote IronPdfEngine), but the Contents and BoundingBox of this span, its line and its block are not recomputed. Read TextBlocks again after editing.
Fragments inside a Form XObject are read-only: edits to them are ignored.
Declaration
public IReadOnlyList<TextObject> Fragments { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IReadOnlyList<TextObject> |