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

MethodDescription
THPDFTable.Create(ADoc: THotPDF)Creates the table bound to the document that supplies pages, fonts, and images
THPDFTable.DestroyFrees the table together with every row and cell it owns
THPDFTable.AddColumn(Width: Single): IntegerAppends a column with the given width in current page units and returns its index
THPDFTable.AddRow: THPDFTableRowAppends 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.RenderMeasures row heights, draws backgrounds, borders, and cell content, and continues on new pages while rows remain

Properties

PropertyDescription
THPDFTable.Doc: THotPDFThe bound document supplied to the constructor
THPDFTable.ColCount: IntegerNumber of columns added with THPDFTable.AddColumn
THPDFTable.RowCount: IntegerNumber of rows added with THPDFTable.AddRow
THPDFTable.Rows[Index: Integer]: THPDFTableRowAccesses a row by index
THPDFTable.X: Single and THPDFTable.Y: SingleTable origin on the page in current page units
THPDFTable.HeaderBgColor: TColorBackground colour painted behind header rows
THPDFTable.AlternatingBg: TColorZebra-stripe background applied to alternating non-header rows
THPDFTable.BorderColor: TColor and THPDFTable.BorderWidth: SingleGrid line colour and width used for cell borders
THPDFTable.DefaultFontName: AnsiString, THPDFTable.DefaultFontSize: Single, THPDFTable.DefaultAlign: THPDFCellAlignFallback font and alignment for cells that do not override them
THPDFTable.Padding: SingleInner spacing between a cell border and its content
THPDFTable.BottomMargin: SingleSpace reserved at the bottom of a page before the render pass breaks to a new page
THPDFTable.RepeatHeader: BooleanWhen true the header band is re-emitted at the top of every continuation page
THPDFTable.TotalHeightRendered: SingleTotal 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

MemberDescription
THPDFTableRow.Create(InitialColCount: Integer)Creates the row pre-populated with the given number of cells
THPDFTableRow.DestroyFrees the row and its cells
THPDFTableRow.AddCell: THPDFTableCellAppends one cell and returns it
THPDFTableRow.EnsureCells(Count: Integer): IntegerGrows the row to at least the given cell count and returns the new count
THPDFTableRow.Cells[Index: Integer]: THPDFTableCellDefault array property accessing a cell by index
THPDFTableRow.Count: IntegerNumber of cells currently held by the row
THPDFTableRow.IsHeader: BooleanMarks the row as a header row painted with THPDFTable.HeaderBgColor and repeated when THPDFTable.RepeatHeader is enabled
THPDFTableRow.MinHeight: SingleLower bound applied to the measured row height

THPDFTableCell

THPDFTableCell carries the content and per-cell overrides applied on top of the table defaults

PropertyDescription
THPDFTableCell.Text: WideStringCell 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: THPDFCellVAlignHorizontal and vertical content alignment inside the cell
THPDFTableCell.ColSpan: Integer and THPDFTableCell.RowSpan: IntegerHorizontal and vertical merge counts, both defaulting to 1
THPDFTableCell.BgColor: TColor and THPDFTableCell.HasBgColor: BooleanPer-cell background colour override and its presence flag
THPDFTableCell.TextColor: TColor and THPDFTableCell.HasTextColor: BooleanPer-cell text colour override and its presence flag
THPDFTableCell.FontName: AnsiString, THPDFTableCell.FontSize: Single, THPDFTableCell.FontStyle: TFontStyles, THPDFTableCell.HasFont: BooleanPer-cell font override and its presence flag
THPDFTableCell.WordWrap: BooleanWraps long text across measured lines inside the cell, enabled by default
THPDFTableCell.ImageIndex: IntegerWhen zero or greater the cell shows the image registered with that index through THotPDF.AddImage instead of text, default -1
THPDFTableCell.ImageAspect: SingleDisplay 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: BooleanRoutes 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

See also