In principle, it is very easy to print using Delphi. You basically draw on the page's canvas as you'd draw on an on-screen canvas using the VCL (that is, using the Windows GDI).
Here is a very simple example:
procedure PrintRects;
const
Offset = 100;
RectCountY = 8;
RectCountX = 4;
var
S: string;
TitleRect: TRect;
MainRect: TRect;
j: Integer;
i: Integer;
RectWidth,
RectHeight: Integer;
R: TRect;
function GetRectRect(X, Y: Integer): TRect;
begin
Result := Rect(
MainRect.Left + X * RectWidth,
MainRect.Top + Y * RectHeight,
MainRect.Left + (X + 1) * RectWidth,
MainRect.Top + (Y + 1) * RectHeight
);
end;
begin
with TPrintDialog.Create(nil) do
try
if not Execute then
Exit;
finally
Free;
end;
Printer.BeginDoc;
try
Printer.Canvas.Font.Size := 42;
S := 'My Collection of Rects';
TitleRect := Rect(
Offset,
Offset,
Printer.PageWidth - Offset,
Offset + 2 * Printer.Canvas.TextHeight(S)
);
MainRect := Rect(
Offset,
TitleRect.Bottom + Offset,
Printer.PageWidth - Offset,
Printer.PageHeight - Offset
);
RectWidth := MainRect.Width div RectCountX;
RectHeight := MainRect.Height div RectCountY;
Printer.Canvas.TextRect(TitleRect, S, [tfSingleLine, tfCenter, tfVerticalCenter]);
for j := 0 to RectCountY - 1 do
for i := 0 to RectCountX - 1 do
begin
R := GetRectRect(i, j);
Printer.Canvas.Brush.Color := RGB(Random(255), Random(255), Random(255));
Printer.Canvas.FillRect(R);
end;
finally
Printer.EndDoc;
end;
end;
This produces the following page:
Needless to say, instead of solid-colour rectangles, you could print your images here in this grid.
Hence, if you know how to draw things on a form (using TCanvas
, that is, Windows GDI), you can use the same methods to draw on a printed page.
And of course, you can call this procedure when you click a button:
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintRects;
end;