The code below works well.
Would like to get a print that fills the entire A4 (landscape).
procedure TFMAIN.SpeedButton1Click(Sender: TObject);
var
myBitMap : TBitMap;
rct: TRect;
HScaleFactor, VScaleFactor: Single;
BWidth, BHeight: Integer;
PWidth, PHeight: Integer;
RTop, RLeft, RBottom, RRight: Integer;
begin
// Put "Math" in uses !!!
if not PrintDialog1.Execute then Exit;
HScaleFactor := Printer.XDPI / Screen.PixelsPerInch;
VScaleFactor := Printer.YDPI / Screen.PixelsPerInch;
try
myBitMap := TBitMap.Create;
Printer.Refresh;
Printer.Orientation:= poLandscape;
myBitMap.LoadFromDevice(FMAIN.Canvas.Handle);
BWidth := trunc(myBitMap.Width*HScaleFactor);
BHeight := trunc(myBitMap.Height*VScaleFactor);
PWidth := Printer.PageWidth;
PHeight := Printer.PageHeight;
RTop := max(0, ((PHeight div 2) - (BHeight div 2)));
RLeft := max(0, ((PWidth div 2) - (BWidth div 2)));
RBottom := min(PHeight, (RTop + BHeight));
RRight := min(PWidth, (RLeft + BWidth));
rct := Rect(Rleft, RTop, RRight, RBottom);
Printer.BeginDoc;
Printer.Canvas.Font.Size:=12;
Printer.Canvas.StretchDraw(rct, myBitMap);
finally
Printer.EndDoc;
myBitMap.Free;
end;
end;