简体   繁体   中英

Delphi XE8 Firemonkey PrinterSetupDialog two pages on one A4

I need to print two pages on one A4 sheet. I am using the PrinterSetupDialog component to set printer options. Then i print two pages using this code below, but both are on separate A4 sheets.

What am I doing wrong?

Im using Delphi XE8 and this is Firemonkey application.

Regards.

Simple print procedure:

var
  SrcRect, DestRect: TRectF;
  vBitmap: TBitmap;
begin
  if PrinterSetupDialog1.Execute then
  begin
    Printer.ActivePrinter.SelectDPI(1200, 1200);

    { Set canvas filling style. }
    Printer.Canvas.Fill.Color := TAlphaColorRec.White;
    Printer.Canvas.Fill.Kind := TBrushKind.Solid;

    { Start printing. }
    Printer.BeginDoc;

    { Set the Destination TRects. }
    DestRect := TRectF.Create(0, 0, Printer.PageWidth, Printer.PageHeight);

    vBitmap := TBitmap.Create;
    try
      { Page 1 }
      vBitmap.LoadFromFile('D:\Page1.bmp');
      SrcRect.Width := vBitmap.Width;
      SrcRect.Height := vBitmap.Height;
      { Print the picture on all the surface of the page and all opaque. }
      Printer.Canvas.DrawBitmap(vBitmap, SrcRect, DestRect, 1);


      { Page 2 }
      vBitmap.LoadFromFile('D:\Page2.bmp');
      SrcRect.Width := vBitmap.Width;
      SrcRect.Height := vBitmap.Height;
      { Add new Page}
      Printer.NewPage;
      { Print the picture on all the surface of the page and all opaque. }
      Printer.Canvas.DrawBitmap(vBitmap, SrcRect, DestRect, 1);
    finally
      vBitmap.Free;
    end;

    { Finish printing job. }
    Printer.EndDoc;
  end;
end;

1 Update

Removing SelectDPI line give me no results.

But i made this code on VCL and it work.

var
  SrcRect, DestRect: TRect;
  vBitmap: TBitmap;
begin
  if PrinterSetupDialog1.Execute then
  begin
    Printer.BeginDoc;

    DestRect := Rect(0, 0, Printer.PageWidth, Printer.PageHeight);

    vBitmap := TBitmap.Create;
    try
      vBitmap.LoadFromFile('D:\Page1.bmp');
      SrcRect := Rect(0, 0, vBitmap.Width, vBitmap.Height);
      Printer.Canvas.CopyRect(DestRect, vBitmap.Canvas, SrcRect);

      Printer.NewPage;

      vBitmap.LoadFromFile('D:\Page2.bmp');
      SrcRect := Rect(0, 0, vBitmap.Width, vBitmap.Height);
      Printer.Canvas.CopyRect(DestRect, vBitmap.Canvas, SrcRect);
    finally
      vBitmap.Free;
    end;

    Printer.EndDoc;
  end;
end;

2 Update

I solved this problem with writing a print module in VCL, but i will describe my observations.

I think it is a bug on my version of Delphi, Settings from FMX.Printer.TPrintDialog and FMX.Printer.TPrinterSettupDialog are ignored while printing. But this components in VCL version works ok, for Windows. I tested on MAC and it works only on FMX.Printer.TPrintDialog , TPrinterSettupDialog not showing up.

Regards.

The reason for the problem is the line

Printer.ActivePrinter.SelectDPI(1200, 1200);

This resets the Pages per sheet setting to 1 (probably/possibly other properties too). Removing the line cures the problem. The DPI setting is available in all printer setup dialogs I have on my system, maybe you can leave it to the users responsibility while they are setting up other properties. Anyway I would not make such a setting hardcoded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM