PDFium Delphi Component Docs

ExtractTables method

Component: TPdf  ·  Unit: PDFium
Detects and extracts table structure from the current PDF page

Syntax

function ExtractTables(
  const Options: TPdfTableExtractionOptions): TPdfTables;

Description

The ruled strategy transforms native stroked path segments into page coordinates, isolates connected grids, and merges adjacent base cells when a local divider is absent

With DetectFilledRulings the same strategy also reads filled geometry: a filled rectangle no thicker than MaxRulingThickness becomes one ruling along its long axis, and a larger filled rectangle such as a shaded cell contributes its four edges. Every ruling coordinate is then snapped within RulingSnapTolerance so per-cell border pieces, double borders, and shaded cells with a small gutter connect into one grid. Word-processor and browser exports draw tables this way, so they are reported as ruled grids rather than whitespace fragments. IncludeFormXObjects walks form XObjects with their combined matrices

The whitespace strategy groups native word boxes into visual rows and requires repeated aligned column anchors across multiple rows. Words already inside a detected ruled grid are excluded, and every column boundary must be a vertical corridor free of text on all rows that have content on both sides, which keeps justified paragraphs from being reported as tables

Each TPdfTable includes page bounds, RowCount and column counts, DetectionMode, confidence, and TPdfTableCell values with text, bounds, the IsHeader state, RowIndex, ColumnIndex, RowSpan, and ColumnSpan

Output

Budgets and tuning

MinRows, MinColumns, AlignmentTolerance, RulingTolerance, MinColumnGap, MaxRowGapFactor, and MinConfidence control detection; MinRows may be 1 for ruled grids, while whitespace detection always needs at least two rows

DetectFilledRulings, MaxRulingThickness, RulingSnapTolerance, and IncludeFormXObjects tune the filled-geometry path; the defaults are on, 3 points, 4 points, and on

MaxWords, MaxRulingSegments, MaxCells, and MaxTables fail closed before unbounded work or allocation

Example

var
  Options: TPdfTableExtractionOptions;
  Tables: TPdfTables;
begin
  Options := TPdfTableExtractionOptions.Default;
  Tables := Pdf1.ExtractTables(Options);
  if Length(Tables) > 0 then
    Memo1.Text := Tables[0].ToCsv;
end;

See Also

ExtractDocumentTables, BuildReflowDocument, GetStructuredText, PageWordBoxes