Merge Reports

Hi

I have 2 reports, lets call them Report1 and Report2

Is it possible to merge those two report into 1 PDF file? I can not put them into one designer since I need 3 copies of Report1 and two copies of Report2?

Comments

  • Hi Jens,

    It is possible to merge multiple reports into a single file using the built-in Device.StartPrintJob and Device.EndPrintJob properties. See the following article for more information and an example.

    http://rbwiki.digital-metaphors.com/output/pdf/how-to-merge-multiple-reports-into-one-pdf/

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi Nico

    That worked very well. Thank You for that.

    Is it possible to have 3 copies of the first report and 2 copies of the second report in the same PDF.
  • Hi Jens,

    This can be done by creating loops around the PrintToDevices calls (or perhaps creating a sub routine to handle it more elegantly). Something like the following.
    var
    lPDFDevice: TppPDFDevice;
    lbFirstReport: Boolean;
    liCopies: Integer;
    liIndex: Integer;
    begin

    lPDFDevice := TppPDFDevice.Create(nil);

    // lPDFDevice.PDFSettings := ppReport1.PDFSettings; // optionally assign PDFSettings from report
    lPDFDevice.PDFSettings.OpenPDFFile := True;
    lPDFDevice.FileName := TppFileUtils.GetApplicationFilePath + 'myReport.PDF';

    lPDFDevice.EndPrintJob := False;
    lPDFDevice.Publisher := ppReport1.Publisher;

    liCopies := StrToInt(Edit1.Text);
    lbFirstReport := True;

    for liIndex := 0 to liCopies - 1 do
    begin
    lPDFDevice.Reset;

    if not(lbFirstReport) then
    lPDFDevice.StartPrintJob := False
    else
    lbFirstReport := False;

    ppReport1.PrintToDevices;
    end;

    liCopies := StrToInt(Edit2.Text);

    lPDFDevice.StartPrintJob := False;
    lPDFDevice.Publisher := ppReport2.Publisher;

    for liIndex := 0 to liCopies - 1 do
    begin
    lPDFDevice.Reset;

    if liIndex = liCopies - 1 then
    lPDFDevice.EndPrintJob := True;

    ppReport2.PrintToDevices;
    end;

    lPDFDevice.Free

    end;
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Here is the more elegant solution I mentioned above :smile: .

    var
    lPDFDevice: TppPDFDevice;
    begin

    lPDFDevice := TppPDFDevice.Create(nil);

    // lPDFDevice.PDFSettings := ppReport1.PDFSettings; // optionally assign PDFSettings from report
    lPDFDevice.PDFSettings.OpenPDFFile := True;
    lPDFDevice.FileName := TppFileUtils.GetApplicationFilePath + 'myReport.PDF';

    MergeCopies(ppReport1, lPDFDevice, StrToInt(Edit1.Text), True, False);
    MergeCopies(ppReport2, lPDFDevice, StrToInt(Edit2.Text), False, True);

    lPDFDevice.Free

    end;

    procedure MergeCopies(aReport: TppReport; aFileDevice: TppFileDevice; aCopies: Integer; aFirstReport, aLastReport: Boolean);
    var
    liIndex: Integer;
    lbFirstReport: Boolean;
    begin

    aFileDevice.StartPrintJob := True;
    aFileDevice.EndPrintJob := False;

    aFileDevice.Publisher := aReport.Publisher;

    lbFirstReport := aFirstReport;

    for liIndex := 0 to aCopies - 1 do
    begin
    aFileDevice.Reset;

    if not(lbFirstReport) then
    aFileDevice.StartPrintJob := False
    else
    lbFirstReport := False;

    if (liIndex = aCopies - 1) and (aLastReport) then
    aFileDevice.EndPrintJob := True;

    aReport.PrintToDevices;

    end;

    end;
    Best Regards,

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