Skip to main content
Table of Contents

Printing

Send the grid to the system printer with TTMSFNCDataGridPrintIO — same options as the PDF exporter, just a different output device.

Populated DataGrid prepared for printed output Populated DataGrid prepared for printed output

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

Send a DataGrid to the system printerPascalC++
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;
using namespace Fmx::Tmsfncdatagridprintio;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  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;
}

void __fastcall TForm1::PrintButtonClick(TObject *Sender)
{
  PrintIO->Print();
}

Step by step

1. Wire the component

Pascal
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.
Pascal
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

Pascal
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

Dynamic page breaks when printingPascalC++
procedure TForm1.PrintIORowIsPageBreak(Sender: TObject;
  AExportObject: TTMSFNCPrintIOExportObject; ARow: Integer;
  var IsPageBreak: Boolean);
begin
  IsPageBreak := IsGroupHeader(ARow);     // your own predicate
end;
using namespace Fmx::Tmsfncdatagridprintio;
void __fastcall TForm1::PrintIORowIsPageBreak(TObject *Sender,
  TTMSFNCPrintIOExportObject *AExportObject, int ARow,
  bool &IsPageBreak)
{
  IsPageBreak = IsGroupHeader(ARow);     // your own predicate
}
Populated DataGrid prepared for printed output Populated DataGrid prepared for printed output

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:

Pascal
PDF.Options.OpenInPDFReader := True;
PDF.Save(TempFileName);
// User reviews in their default PDF viewer, then prints from there.
  • TTMSFNCDataGridPrintIO
  • PrintIO.Print
  • PrintIO.Options.Scale / FitToPage
  • PrintIO.Options.RepeatFixedRows / RepeatFixedColumns
  • PrintIO.Options.Header / Footer
  • OnRowIsPageBreak
  • OnBeforeDrawContent, OnAfterDrawContent
  • OnGetHeader, OnGetFooter

See also

  • PDF export — same options, file-based output with preview.
  • Demo: Demo/FMX/DataGrid/Basic/PDF Export (illustrates the printing path too).