Interface IPdfTextObjectCollection
Collection of PDF text objects
Namespace: IronSoftware
Assembly: IronPdf.dll
Syntax
public interface IPdfTextObjectCollection : IDocumentTextObjectCollection<TextObject>, IEnumerable<TextObject>, IEnumerable, IList<TextObject>, ICollection<TextObject>, IJsonSerializable
Reading a page's text DOM as a list of IronSoftware.TextObject elements runs through IPdfTextObjectCollection, the value returned from IronPdf.Pages.PdfPage.Lines and IronPdf.Pages.PdfPage.TextChunks. Every list operation defined on IList<T> is available on instances returned from the IronPDF page model.
IPdfTextObjectCollection is the type a caller works with whenever code reads or rewrites the per-line or per-run text DOM of a page. Typical scenarios include enumerating each line on a page to reconstruct columns during PDF layout analysis, indexing into a specific line to read its Contents and BoundingBox during search-result highlighting, and counting text runs on a page before deciding whether to call PdfExtractor or to walk the DOM directly. The contract is paired with the concrete IronSoftware.TextObjectCollection (an ObservableCollection<TextObject> that implements this interface), and sits alongside IPdfImageObjectCollection and IPdfPathObjectCollection as the three page-DOM containers in the IronSoftware namespace.
To consume IPdfTextObjectCollection, open a PdfDocument, enumerate PdfDocument.Pages, and access PdfPage.Lines for line-level grouping or PdfPage.TextChunks for per-run granularity. The contract carries no declarations of its own; every callable member is inherited from IList<TextObject> (the indexer this[int], Count, Contains, IndexOf, CopyTo), ICollection<TextObject> (Add, Remove, RemoveAt, Clear, IsReadOnly), and IJsonSerializable (ToJson). The docfx remarks describe PdfPage.Lines as "derived from TextChunks by grouping text objects that appear on the same visual line based on their vertical position", so each access returns a freshly-grouped collection rather than a live view of page state. For the surrounding extraction workflow, see the extract text and images how-to.
using IronPdf;
using IronPdf.Pages;
using IronSoftware;
PdfDocument pdf = PdfDocument.FromFile("invoice.pdf");
foreach (PdfPage page in pdf.Pages)
{
IPdfTextObjectCollection lines = page.Lines;
System.Console.WriteLine($"Page {page.PageNumber}: {lines.Count} lines");
for (int i = 0; i < lines.Count; i++)
{
TextObject line = lines[i];
System.Console.WriteLine($" [{i}] \"{line.Contents}\" at {line.BoundingBox}");
}
}Walking the sibling IPdfImageObjectCollection and IPdfPathObjectCollection containers in the same pass is shown in the access PDF DOM object how-to. When the goal is editing text in place rather than enumerating the line collection, the find and replace text in PDF how-to has worked ReplaceTextOnAllPages and ReplaceTextOnPage examples.