Conditionally merging PDF reports

edited July 2013 in Devices
I am using ReportBuilder Enterprise 14.08 and Delphi XE2.

I am looking for help with a set of reports where I want to
conditionally merge some of the PDF reports in a set of multiple reports
into a single PDF file. That is to say, some of the reports in this set
should be merged, others not based on the report's specifications.

Below is the code I am using to try to accomplish this. However it does
not correctly work. It works correctly when no reports are merged.
However when I choose to merge a subset of the reports, they report is
not correctly closed and thus is not useable.

In the example below, the query, quMyReportSet is a data set defining
the reports to print. Based on the specifications, the report is
dynamically created and it's attendent data set is prepared.

quMyReportSet contains a column ReportGroup which defines how the
reports are grouped. As long as the report's ReportGroup value is the
same is the prior report, this report should be merged with the prior
report.

When the ReportGroup value changes, the merged report document should be
closed and a new report document started.

The code below does not work when the ReportGroup value changes - the
prior report is not closed and the new report is not "opened".
But I can't see what needs to be done to fix this.

Code sample. . . .

procedure TfmReports.RunSelectedReportsPDF;
var
ThisPDFDevice: TppPDFDevice;
SaveReportGroup: string;
First: boolean;
begin
try
First := true;
ThisPDFDevice := TppPDFDevice.Create(nil);
ThisPDFDevice.PDFSettings := dmReports.rbReport.PDFSettings;
ThisPDFDevice.Publisher := dmReports.rbReport.Publisher; // all
reports use the same rbReport component

quMyReportSet.First; // data set containing report definitions
while not quMyReportset.eof do // loop through the reports. Each
row defines a report
begin
if quMyReportSet.Fieldbyname('ISSelected').AsString = 'Y' then
// user has option to select/not select a desired report
begin
ThisPDFDevice.Publisher := dmReports.rbReport.Publisher;
if First then
begin
ThisPDFDevice.StartPrintJob := true;
ThisPDFDevice.EndPrintJob := false;
SaveReportGroup :=
quMyReportSet.FieldByName('ReportGroup').AsString;
first := false;
end
else
if SaveReportGroup <>
quMyReportSet.FieldByName('ReportGroup').AsString then // ReportGroup
value has changed
begin
SaveReportGroup :=
quMyReportSet.FieldByName('ReportGroup').AsString;
ThisPDFDevice.StartPrintJob := true;
ThisPDFDevice.EndPrintJob := false;
end
else // ReportGroup value is same as prior report
begin
ThisPDFDevice.StartPrintJob := false;
ThisPDFDevice.EndPrintJob := false;
end;

SetReportDetails(true);
ReportDetails.ReportOption := roPDFGroup;
ThisPDFDevice.FileName := ReportDetails.ReportFileName;
RunSelectedReport; // generate the report per specs


end;
quMyReportset.next;
end; // end of dataset loop
finally
ThisPDFDevice.EndPrintJob := True;
ThisPDFDevice.EndJob;
Freeandnil(ThisPDFDevice);
end;
end;


Thanks,
Phil Horst

Comments

  • edited July 2013
    Hi Phil,

    I do not see anywhere in the loop that you are setting
    ThisPDFDevice.EndPrintJob to True. It is necessary to set this to True
    to finalize and create a separate file.

    You may need another case where you look ahead in your dataset and see
    if the group has changed. If so, set the StartPrintJob := False; and
    EndPrintJob := True; before printing the last report in the group.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.