procedure TForm1.btn2Click(Sender: TObject);
var
printDialog : TPrintDialog;
myPrinter : TPrinter;
size1, size2: TSize;
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
size1 := Canvas.TextExtent('Page width = '+IntToStr(PageWidth));
size2 := Canvas.TextExtent('Page height = '+IntToStr(PageHeight));
Canvas.TextOut(20, 20, 'size1 is x:' + IntToStr(size1.cx) + 'and y:' + IntToStr(size1.cy));
Canvas.TextOut(20, 190, 'size2 is x:' + IntToStr(size2.cx) + 'and y:' + IntToStr(size2.cy));
Canvas.TextOut(20, 380, 'Page width = '+IntToStr(PageWidth));
Canvas.TextOut(20, 570, 'Page height = '+IntToStr(PageHeight));
// Finish printing
EndDoc;
end;
end;
end;