Manually duplicating report inside OnPrintReport event
Hello,
I need to print multiple copies of a single report however each copy needs to be a little different. After preparing the report and showing it in preview window, the user selects how many copies to print inside the print dialog and starts printing. Then FastReport fires OnPrintReport event which needs to build the whole report again, once for each copy.
However this only happens if I show the preview window (with frxReport.ShowPreparedReport) before printing.
If I print directly (with frxReport.Print) then everything works fine.
Any ideas how to solve this? I'm using FastReport 5.4 Standard so I can't check the source code.
Thanks!
I need to print multiple copies of a single report however each copy needs to be a little different. After preparing the report and showing it in preview window, the user selects how many copies to print inside the print dialog and starts printing. Then FastReport fires OnPrintReport event which needs to build the whole report again, once for each copy.
procedure TForm1.frxReportPrintReport(Sender: TObject);
var
  copyNumber: Integer;
begin
  frxReport.PreviewPages.Clear;
  for copyNumber := 1 to frxReport.PrintOptions.Copies do
  begin
    UpdateReportDataForSpecificCopy(copyNumber);
    frxReport.PrepareReport(False);
  end;
  //reset copies because report was duplicated manually
  frxReport.PrintOptions.Copies := 1;
end;
The problem is that each PrepareReport(False) overwrites the previous one and in the end prints only the last copy.However this only happens if I show the preview window (with frxReport.ShowPreparedReport) before printing.
If I print directly (with frxReport.Print) then everything works fine.
Any ideas how to solve this? I'm using FastReport 5.4 Standard so I can't check the source code.
Thanks!
Comments
I don't see the advantage of using the same TfrxReport class to print that batch of report. Could you simply use another class to print that batch and stop the current printing of the generic report?
I'm not sure if it is possible without the source code, but you could also inherit the TfrxPreviewForm and modify the behavior of the print button for that particular report(and to link that PreviewForm to your TfrxReport). What I do is that I use my own PreviewForm (created from scratch) that I can customize to my liking.
Used in production for about a month and it works great. Although it's rarely used to print more than 3 pages in total.