THPDFTable Table Layout and Rendering
THPDFTable is the lightweight table layout and rendering engine introduced in v2.429.0 and exposed by the HPDFTable unit
Before v2.429.0 producers had to hand-draw cells with Rectangle plus TextOut and hardcoded column X coordinates, managing row heights, zebra striping, and page breaks manually; THPDFTable drives the existing THPDFPage drawing primitives so tables render with measured row heights, merged cells, and automatic page-break continuation
Unit
HPDFTable
Using example
uses
HPDFTable;
var
Tbl: THPDFTable;
Row: THPDFTableRow;
begin
Tbl:= THPDFTable.Create(HPDF);
try
Tbl.AddColumn(80); Tbl.AddColumn(200); Tbl.AddColumn(120);
Tbl.SetBounds(50, 60);
Row:= Tbl.AddRow; Row.IsHeader:= True;
Row.Cells[0].Text:= 'No';
Row.Cells[1].Text:= 'Description';
Row:= Tbl.AddRow;
Row.Cells[0].ColSpan:= 2; // merged cell across columns 0..1
Row.Cells[0].Text:= 'merged header';
Tbl.Render;
finally
Tbl.Free;
end;
end;
THPDFTable
THPDFTable owns the column layout, the row collection, and the render pass; it draws through the THotPDF component passed to THPDFTable.Create and uses only public THPDFPage and THotPDF members
Methods
| Method | Description |
|---|---|
THPDFTable.Create(ADoc: THotPDF) | Creates the table bound to the document that supplies pages, fonts, and images |
THPDFTable.Destroy | Frees the table together with every row and cell it owns |
THPDFTable.AddColumn(Width: Single): Integer | Appends a column with the given width in current page units and returns its index |
THPDFTable.AddRow: THPDFTableRow | Appends a row sized to the current column count and returns it |
THPDFTable.SetBounds(AX, AY: Single) | Positions the table origin on the current page |
THPDFTable.Render | Measures row heights, draws backgrounds, borders, and cell content, and continues on new pages while rows remain |
Properties
| Property | Description |
|---|---|
THPDFTable.Doc: THotPDF | The bound document supplied to the constructor |
THPDFTable.ColCount: Integer | Number of columns added with THPDFTable.AddColumn |
THPDFTable.RowCount: Integer | Number of rows added with THPDFTable.AddRow |
THPDFTable.Rows[Index: Integer]: THPDFTableRow | Accesses a row by index |
THPDFTable.X: Single and THPDFTable.Y: Single | Table origin on the page in current page units |
THPDFTable.HeaderBgColor: TColor | Background colour painted behind header rows |
THPDFTable.AlternatingBg: TColor | Zebra-stripe background applied to alternating non-header rows |
THPDFTable.BorderColor: TColor and THPDFTable.BorderWidth: Single | Grid line colour and width used for cell borders |
THPDFTable.DefaultFontName: AnsiString, THPDFTable.DefaultFontSize: Single, THPDFTable.DefaultAlign: THPDFCellAlign | Fallback font and alignment for cells that do not override them |
THPDFTable.Padding: Single | Inner spacing between a cell border and its content |
THPDFTable.BottomMargin: Single | Space reserved at the bottom of a page before the render pass breaks to a new page |
THPDFTable.RepeatHeader: Boolean | When true the header band is re-emitted at the top of every continuation page |
THPDFTable.TotalHeightRendered: Single | Total height consumed by the last render pass across all pages |
THPDFTableRow
THPDFTableRow holds the cells of one table row plus the row-level flags used during measurement and rendering
| Member | Description |
|---|---|
THPDFTableRow.Create(InitialColCount: Integer) | Creates the row pre-populated with the given number of cells |
THPDFTableRow.Destroy | Frees the row and its cells |
THPDFTableRow.AddCell: THPDFTableCell | Appends one cell and returns it |
THPDFTableRow.EnsureCells(Count: Integer): Integer | Grows the row to at least the given cell count and returns the new count |
THPDFTableRow.Cells[Index: Integer]: THPDFTableCell | Default array property accessing a cell by index |
THPDFTableRow.Count: Integer | Number of cells currently held by the row |
THPDFTableRow.IsHeader: Boolean | Marks the row as a header row painted with THPDFTable.HeaderBgColor and repeated when THPDFTable.RepeatHeader is enabled |
THPDFTableRow.MinHeight: Single | Lower bound applied to the measured row height |
THPDFTableCell
THPDFTableCell carries the content and per-cell overrides applied on top of the table defaults
| Property | Description |
|---|---|
THPDFTableCell.Text: WideString | Cell text; rendered through THPDFPage.TextOutHTML when THPDFTableCell.IsHTML is true so inline markup for bold, colour, links, and sub-sup is honoured |
THPDFTableCell.Align: THPDFCellAlign and THPDFTableCell.VAlign: THPDFCellVAlign | Horizontal and vertical content alignment inside the cell |
THPDFTableCell.ColSpan: Integer and THPDFTableCell.RowSpan: Integer | Horizontal and vertical merge counts, both defaulting to 1 |
THPDFTableCell.BgColor: TColor and THPDFTableCell.HasBgColor: Boolean | Per-cell background colour override and its presence flag |
THPDFTableCell.TextColor: TColor and THPDFTableCell.HasTextColor: Boolean | Per-cell text colour override and its presence flag |
THPDFTableCell.FontName: AnsiString, THPDFTableCell.FontSize: Single, THPDFTableCell.FontStyle: TFontStyles, THPDFTableCell.HasFont: Boolean | Per-cell font override and its presence flag |
THPDFTableCell.WordWrap: Boolean | Wraps long text across measured lines inside the cell, enabled by default |
THPDFTableCell.ImageIndex: Integer | When zero or greater the cell shows the image registered with that index through THotPDF.AddImage instead of text, default -1 |
THPDFTableCell.ImageAspect: Single | Display aspect ratio for an image cell; the image is scaled to the cell width and its height derives from this ratio, default 1.0 |
THPDFTableCell.IsHTML: Boolean | Routes THPDFTableCell.Text through THPDFPage.TextOutHTML so inline markup is rendered |
Alignment enums
THPDFCellAlign = (caLeft, caCenter, caRight) selects horizontal cell alignment and THPDFCellVAlign = (cvaTop, cvaMiddle, cvaBottom) selects vertical cell alignment
Layout and page-break behaviour
Row heights are measured from cell content with word wrap and THPDFTableRow.MinHeight honoured, spanning cells are placed on an internal grid so THPDFTableCell.ColSpan and THPDFTableCell.RowSpan merge correctly across rows, and the render pass breaks to a new page when the next row does not fit above THPDFTable.BottomMargin
When THPDFTable.RepeatHeader is true the header band is re-emitted at the top of every continuation page before further rows are drawn
Image cells introduced in v2.432.0 reference an image registered through THotPDF.AddImage by index, scale to the cell width, and derive their height from THPDFTableCell.ImageAspect so the picture keeps its source aspect ratio