program TableDemo;
{$APPTYPE CONSOLE}
{ Reduce EXE size by disabling as much of RTTI as possible }
{$IFDEF VER210}
{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
{$ENDIF}
uses
{$IFDEF VER230}System.Classes, System.SysUtils, Vcl.Graphics, DB, DBTables,
{$ELSE} Classes, SysUtils, Graphics, DB, DBTables,
{$ENDIF} HPDFDoc;
var
HotPDF: THotPDF;
PageNum, VertPos: Integer;
CustomerTable: TTable;
Back: boolean;
procedure PrintRow(Position: Integer; No, Company, Addr, City: AnsiString; ShowBackground: boolean);
begin
if ShowBackground then
begin
HotPDF.CurrentPage.SetRGBColor($FFF3DD);
HotPDF.CurrentPage.Rectangle(50, Position, 520, 20);
HotPDF.CurrentPage.Fill;
HotPDF.CurrentPage.SetRGBColor(clBlack);
end;
HotPDF.CurrentPage.TextOut(70, Position, 0, No);
HotPDF.CurrentPage.TextOut(110, Position, 0, Company);
HotPDF.CurrentPage.TextOut(300, Position, 0, Addr);
HotPDF.CurrentPage.TextOut(480, Position, 0, City);
end;
procedure PreparePage;
begin
HotPDF.CurrentPage.SetFont('Arial', [fsItalic], 10);
HotPDF.CurrentPage.TextOut(50, VertPos, 0, 'customer.db' + ' Page' + AnsiString(IntToStr(PageNum)));
HotPDF.CurrentPage.TextOut(480, VertPos, 0, AnsiString(DateTimeToStr(Now)));
HotPDF.CurrentPage.MoveTo(50, VertPos + 15);
HotPDF.CurrentPage.LineTo(570, VertPos + 15);
HotPDF.CurrentPage.MoveTo(50, VertPos + 45);
HotPDF.CurrentPage.LineTo(570, VertPos + 45);
HotPDF.CurrentPage.Stroke;
HotPDF.CurrentPage.SetFont('Times New Roman', [fsItalic, fsBold], 12);
HotPDF.CurrentPage.SetRGBFillColor(clNavy);
PrintRow(VertPos + 25, 'No', 'Company', 'Addr', 'City', false);
HotPDF.CurrentPage.SetRGBFillColor(clBlack);
Inc(VertPos, 20);
end;
begin
CustomerTable := TTable.Create(nil);
try
CustomerTable.DatabaseName := 'DBDEMOS';
CustomerTable.TableName := GetCurrentDir + '\customer.db';
CustomerTable.Active := true;
CustomerTable.First;
HotPDF := THotPDF.Create(nil);
try
HotPDF.AutoLaunch := true;
HotPDF.FileName := 'TableDemo.pdf';
HotPDF.PageLayout := plOneColumn;
HotPDF.BeginDoc;
HotPDF.CurrentPage.SetFont('Arial', [fsBold], 24);
HotPDF.CurrentPage.TextOut(200, 20, 0, 'Customer report'); // Print PDF header
PageNum := 1;
VertPos := 60;
PreparePage; // Table header
Back := true;
while (not(CustomerTable.Eof)) do
begin
Back := not(Back);
if (VertPos > 700) then // If end of page then
begin
HotPDF.AddPage; // Add page, draw and print
Inc(PageNum); // table header and set
VertPos := 60; // new print position
PreparePage;
end;
PrintRow(VertPos + 25, // print row from the current position
AnsiString(CustomerTable.FieldValues['CustNo']), AnsiString(CustomerTable.FieldValues['Company']),
AnsiString(CustomerTable.FieldValues['Addr1']), AnsiString(CustomerTable.FieldValues['City']), Back);
Inc(VertPos, 20);
CustomerTable.Next;
end;
HotPDF.EndDoc;
finally
HotPDF.Free;
end;
finally
CustomerTable.Free;
end;
end.