Recent

Author Topic: Print Form Landscape A4  (Read 1288 times)

seghele0

  • Full Member
  • ***
  • Posts: 137
Print Form Landscape A4
« on: January 10, 2022, 11:17:09 am »
The code below works well.
Would like to get a print that fills the entire A4 (landscape).

Code: Pascal  [Select][+][-]
  1. procedure TFMAIN.SpeedButton1Click(Sender: TObject);
  2. var
  3.   myBitMap : TBitMap;
  4.   rct: TRect;
  5.   HScaleFactor, VScaleFactor: Single;
  6.   BWidth, BHeight: Integer;
  7.   PWidth, PHeight: Integer;
  8.   RTop, RLeft, RBottom, RRight: Integer;
  9. begin
  10.   // Put "Math" in uses !!!
  11.   if not PrintDialog1.Execute then Exit;
  12.   HScaleFactor := Printer.XDPI / Screen.PixelsPerInch;
  13.   VScaleFactor := Printer.YDPI / Screen.PixelsPerInch;
  14.   try
  15.     myBitMap := TBitMap.Create;
  16.     Printer.Refresh;
  17.     Printer.Orientation:= poLandscape;
  18.     myBitMap.LoadFromDevice(FMAIN.Canvas.Handle);
  19.     BWidth  := trunc(myBitMap.Width*HScaleFactor);
  20.     BHeight := trunc(myBitMap.Height*VScaleFactor);
  21.     PWidth  := Printer.PageWidth;
  22.     PHeight := Printer.PageHeight;
  23.     RTop    := max(0, ((PHeight div 2) - (BHeight div 2)));
  24.     RLeft   := max(0, ((PWidth div 2) - (BWidth div 2)));
  25.     RBottom := min(PHeight, (RTop + BHeight));
  26.     RRight  := min(PWidth, (RLeft + BWidth));
  27.     rct := Rect(Rleft, RTop, RRight, RBottom);
  28.     Printer.BeginDoc;
  29.     Printer.Canvas.Font.Size:=12;
  30.     Printer.Canvas.StretchDraw(rct, myBitMap);
  31.   finally
  32.     Printer.EndDoc;
  33.     myBitMap.Free;
  34.   end;
  35. end;                        

howardpc

  • Hero Member
  • *****
  • Posts: 3984
Re: Print Form Landscape A4
« Reply #1 on: January 10, 2022, 12:00:49 pm »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TFMAIN.SpeedButton1Click(Sender: TObject);
  2. var
  3.   myBitMap : TBitMap;
  4. begin
  5.   if not PrintDialog1.Execute then Exit;
  6.   myBitMap := TBitMap.Create;
  7.   try
  8.     Printer.Refresh;
  9.     Printer.Orientation:= poLandscape;
  10.     myBitMap.LoadFromDevice(FMAIN.Canvas.Handle);
  11.     Printer.BeginDoc;
  12.     Printer.Canvas.Font.Size := 12;
  13.     Printer.Canvas.StretchDraw(Printer.PaperSize.PaperRect.WorkRect, myBitMap);
  14.   finally
  15.     Printer.EndDoc;
  16.     myBitMap.Free;
  17.   end;
  18. end;

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Print Form Landscape A4
« Reply #2 on: January 10, 2022, 01:40:07 pm »
 :)
THANK YOU.
Many thanks for the solution via your code.
 ;)

 

TinyPortal © 2005-2018