Printing
Send the grid to the system printer with
TTMSFNCDataGridPrintIO— same options as the PDF exporter, just a different output device.
Overview
TTMSFNCDataGridPrintIO mirrors TTMSFNCDataGridPDFIO but routes content
to the system printer instead of writing a file. Drop the component, point
DataGrid at the grid, configure Options, and call Print. The OS print
dialog handles printer selection, page range, and copies.
Quick example
procedure TForm1.FormCreate(Sender: TObject);
begin
PrintIO.DataGrid := Grid;
// Repeat fixed rows/columns on every printed page so each sheet has headers.
PrintIO.Options.RepeatFixedRows := True;
PrintIO.Options.RepeatFixedColumns := True;
// Default: scale the content to fit the printable page width.
PrintIO.Options.FitToPage := True;
end;
procedure TForm1.PrintButtonClick(Sender: TObject);
begin
PrintIO.Print;
end;
Step by step
1. Wire the component
PrintIO.DataGrid := Grid;
2. Configure scaling and headers
| Option | Default | Effect |
|---|---|---|
Scale |
1.0 |
Uniform scale factor. Values below 1.0 shrink the output. |
FitToPage |
True |
Fit grid width to the printable page width. |
RepeatFixedRows |
False |
Repeat fixed rows as column headers on every printed page. |
RepeatFixedColumns |
False |
Repeat fixed columns at the left margin of every printed page. |
Header |
'' |
Static header text printed above the grid on every page. |
Footer |
'' |
Static footer text printed below the grid on every page. |
PrintIO.Scale := 0.85; // shrink to 85% to fit wide grids
PrintIO.FitToPage := True; // also fit width to page
PrintIO.RepeatFixedRows := True; // column headers on every page
PrintIO.Header := 'Sales Report — ' + FormatDateTime('yyyy-mm-dd', Now);
PrintIO.Footer := 'Confidential';
3. Print
PrintIO.Print;
This brings up the OS print dialog. The user picks the printer, page range, and number of copies; the grid handles pagination, fitting, and rendering.
4. Dynamic page breaks
procedure TForm1.PrintIORowIsPageBreak(Sender: TObject;
AExportObject: TTMSFNCPrintIOExportObject; ARow: Integer;
var IsPageBreak: Boolean);
begin
IsPageBreak := IsGroupHeader(ARow); // your own predicate
end;
Print preview
Build a preview workflow with the PDF exporter: write the grid to a temporary PDF, open it in the user's default PDF viewer, and let them print from there:
PDF.Options.OpenInPDFReader := True;
PDF.Save(TempFileName);
// User reviews in their default PDF viewer, then prints from there.
Related API
TTMSFNCDataGridPrintIOPrintIO.PrintPrintIO.Options.Scale/FitToPagePrintIO.Options.RepeatFixedRows/RepeatFixedColumnsPrintIO.Options.Header/FooterOnRowIsPageBreakOnBeforeDrawContent,OnAfterDrawContentOnGetHeader,OnGetFooter
See also
- PDF export — same options, file-based output with preview.
- Demo:
Demo/FMX/DataGrid/Basic/PDF Export(illustrates the printing path too).