AutoFitTableColumns

Page layout, Tables

Description

Measures styled table cell content and assigns every column a width that exactly fills the requested table width

Syntax

Delphi

Function TPDFlib.AutoFitTableColumns(TableID: Integer; TotalWidth, MinColumnWidth, MaxColumnWidth: Double): Integer;

ActiveX

Function PDFlib::AutoFitTableColumns(TableID As Long, TotalWidth As Double, MinColumnWidth As Double, MaxColumnWidth As Double) As Long

DLL

int DLAutoFitTableColumns(int InstanceID, int TableID, double TotalWidth, double MinColumnWidth, double MaxColumnWidth);

Parameters

TableIDHandle returned by CreateTable
TotalWidthExact total width to distribute across all columns in the current coordinate system
MinColumnWidthPositive hard minimum applied to every column
MaxColumnWidthHard maximum applied to every column and not less than MinColumnWidth

Return values

Returns 1 when widths are assigned, or 0 for an unknown table, non-finite values, invalid bounds, or an infeasible total width

Remarks

Cell text is measured with the same HTML fonts, inline styles, text sizes, colors, and horizontal padding used by table drawing

Single-column cells establish preferred widths first, followed by progressively wider merged cells that add constraints across their column spans

If preferred widths exceed TotalWidth, columns shrink proportionally toward MinColumnWidth; spare width is distributed among columns that have not reached MaxColumnWidth

A rejected call is atomic and preserves every existing column width

Example

TableID:= PDF.CreateTable(20, 3);
PDF.SetTableCellContent(TableID, 1, 1, 'Item');
PDF.SetTableCellContent(TableID, 1, 2, 'Description');
PDF.SetTableCellContent(TableID, 1, 3, 'Amount');
if PDF.AutoFitTableColumns(TableID, 495, 60, 300)= 1 then
  PDF.DrawTableRows(TableID, 50, 780, 700, 1, 0);

See also

CreateTable, SetTableColumnWidth, MergeTableCells, DrawTableRows