Returns a reference to the global Printer object Printers unit
 function Printer : TPrinter;
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
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Printing the page width and height text strings onto a page
  printDialog : TPrintDialog;
  myPrinter   : TPrinter;

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

  // If the user has selected a printer (or default), then print!
  if printDialog.Execute then
    // 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
      // Start printing

      // 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
Show full unit code
   A page will be printed with big blue text at the top left:
   Page  width = 2400
   Page height = 3357
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page