SmartPascal
Printer
Function
Returns a reference to the global Printer object Printers unit
 function Printer : TPrinter;
Description
The Printer function returns a reference to the global Printer (TPrinter) object.
 
This object has many methods and properties that you can use to manage printing. In particular:
 
BeginDoc  : Start printing
EndDoc  : Finish printing
NewPage  : Start a new page
PageHeight  : The page canvas height in pixels
PageWidth  : The page canvas width  in pixels
Canvas.Font  : Used to set font size/colour etc
Canvas.Draw  : Draw a graphic on the page
Canvas.TextOut  : Write text to the page

 
You should use TPrintDialog to show the user a printer selection and configuration dialog before printing, as in the example.
Related commands
TObject The base class type that is ancestor to all other classes
 
Example code : Printing the page width and height text strings onto a page
var
  printDialog : TPrintDialog;
  myPrinter   : TPrinter;

begin
  // Create a printer selection dialog
  printDialog := TPrintDialog.Create(Form1);

  // If the user has selected a printer (or default), then print!
  if printDialog.Execute then
  begin
    // Use the Printer function to get access to the
    // global TPrinter object.
    // All references below are to the TPrinter object
    myPrinter := Printer;
    with myPrinter do
    begin
      // Start printing
      BeginDoc;

      // Set up a large blue font
      Canvas.Font.Size   := 20;
      Canvas.Font.Color  := clBlue;

      // Write out the page size
      Canvas.TextOut(20,  20, 'Page  width = '+IntToStr(PageWidth));
      Canvas.TextOut(20, 150, 'Page height = '+IntToStr(PageHeight));

      // Finish printing
      EndDoc;
    end;
  end;
end;
Show full unit code
   A page will be printed with big blue text at the top left:
  
   Page  width = 2400
   Page height = 3357