Search Results for

    Show / Hide Table of Contents

    Class TextBlock

    Block of text lines grouped by vertical proximity (PyMuPDF-style block).

    Inheritance
    System.Object
    TextBlock
    Namespace: IronSoftware
    Assembly: IronPdf.dll
    Syntax
    public class TextBlock : Object

    Grouped text extraction from a PDF page becomes navigable when TextBlock organizes adjacent TextLine objects into a single spatial unit. Each TextBlock represents a cluster of lines that fall within close vertical proximity, mirroring the block model used by PyMuPDF, and gives code a structured way to reason about paragraphs, columns, and captions rather than raw character streams.

    BoundingBox exposes a RectangleF describing the rectangle that encloses all lines in the block, useful for coordinate-based filtering or layout analysis. Contents collapses every line into a single string, giving quick access to the block's full text without iterating Lines. Index records the block's position in the sequence returned by the extraction call, so ordering is always recoverable. Lines provides an IReadOnlyList<TextLine> for per-line inspection, letting code examine individual line positions, text, or spacing within the block.

    using IronPdf;
    
    foreach (TextBlock block in PdfDocument.FromFile("report.pdf").Pages[0].GetTextBlocks())
    {
        if (block.BoundingBox.Y < 100)
            Console.WriteLine($"Header block {block.Index}: {block.Contents}");
    }

    The IReadOnlyList<TextLine> surface on Lines pairs naturally with LINQ, making it straightforward to filter blocks by line count, bounding-box position, or keyword presence. Because BoundingBox uses page-coordinate units consistent with IronPDF's rendering pipeline, the same rectangle can drive annotation placement or region-based redaction without coordinate conversion.

    Explore related techniques at the IronPDF text extraction how-to and browse runnable samples at the PDF text extraction examples.

    Constructors

    TextBlock()

    Declaration
    public TextBlock()

    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 lines in this block, separated by a newline.

    Declaration
    public string Contents { get; }
    Property Value
    Type Description
    System.String

    Index

    Zero based index of this block on the page.

    Declaration
    public int Index { get; }
    Property Value
    Type Description
    System.Int32

    Lines

    Lines in this block, top first.

    Declaration
    public IReadOnlyList<TextLine> Lines { get; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyList<TextLine>
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget