Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

TppPrinterDevice to Preview

Hello,

I need to combine two different reports and show them on screen to the user.

In the code below, how could I do this? Or would there be a better alternative?


procedure TForm1.Button1Click(Sender: TObject);
var
lPrinterDevice: TppPrinterDevice;
begin
lPrinterDevice := TppPrinterDevice.Create(Self);
lPrinterDevice.Stackable := True;

{assign printer device's printer to report - note: do not use assign here}
ppReport.PrinterSetup.PrinterName := lPrinterDevice.Printer.PrinterSetup.PrinterName;
ppReport.PrinterSetup.Copies := lPrinterDevice.Printer.PrinterSetup.Copies;

{print first report}
lPrinterDevice.StartPrintJob := True;
lPrinterDevice.EndPrintJob := False;
lPrinterDevice.Publisher := ppReport.Publisher;
ppReport.PrintToDevices;

{print last report}
lPrinterDevice.StartPrintJob := False;
lPrinterDevice.EndPrintJob := True;
lPrinterDevice.Publisher := ppReport.Publisher;
ppReport.PrintToDevices;

{free device}
lPrinterDevice.Free;
end;

Comments

  • Hi Ueliton,

    When merging two reports on screen there are two main options:

    1. Create a parent report with multiple Section subreports inside the detail band. Load each report template into each subreport before printing to screen.

    2. Use the built-in archive merge utility to generate and merge multiple reports to a single archive and view in the previewer. TppArchiveReader.MergeUtility.
          const
    cTestDir = 'C:\Users\Public\Documents\RBuilder\Delphi 10.3\Demos\1. Reports\Archives\';
    var
    lRAFMerge: TppRAFMerge;

    begin

    lRAFMerge := TppRAFMerge.Create;

    try
    lRAFMerge.DestinationFile := cTestDir + 'TestMerge.raf';

    lRAFMerge.SourceFiles.Add(cTestDir + 'dm0011.raf');
    lRAFMerge.SourceFiles.Add(cTestDir + 'dm0017.raf');
    lRAFMerge.SourceFiles.Add(cTestDir + 'dm0033.raf');

    // options
    // lRAFMerge.DeleteSourceFiles := True;
    // lRAFMerge.RenumberPages := True;


    lRAFMerge.Execute;

    finally
    lRAFMerge.Free;
    end;

    end;
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
Sign In or Register to comment.