Multiple Report Printing with correct Page 1 of X numbering per report

Category

Rave - General

Question

I've followed the other tips and tricks for printing multiple reports as a single print job but I want the Page 1 of X to reflect accurately the page number for each individual report. How do I do that?

Solution

(Before reading this tip and trick you should first familiarize yourself with the following tips and tricks:
Printing Multiple Rave Reports as a single print job.
Multiple reports as single print job with changes in orientation
PIVars and Page Counts for RAVE Report Subsets )

There are two issues that need to be addressed in order to do this. The first is that you need the start page to reflect the current page of the current report only and the second issue is that you want the total pages to only reflect the total pages of each individual report. Not to worry. This can be done fairly simply.

The first thing that you are going to want to do is go into your rave file and create a PIVar, which you would name something like TotalPages. This variable will be used to reflect the total number of pages for each report. Then drop down a DataText component and use the following definition for the DataField property: 'Page' & Report.RelativePage & 'of' & PIVar.TotalPages. (The &'s tell rave to add the values together with a space inbetween.) You will want to change the order in the tree so that this datatext component is the first component that will print. You can do this by right-clicking on it and selecting Order | Send to Back.

Then in a body footer for the report drop down a CalcOp component. Set the DestPIVar to point to the TotalPages PIVar that you have previously defined. and set the Src1DataField to point to the Report.RelativePage variable. You can drop the CalcOp into an existing body footer band. If you don't already have one then you should add one. If you don't want it taking up any space in the report then after you have dropped the CalcOp component into the band simply set the height of the band to zero. Now save the file.

The only remaining change that needs to be made is that in the OnPrint event of the TReportSystem component you will need to add PageNumOffset := 1 - CurrentPage; after calling NewPage and before calling the Execute method of the TRaveProject component as illustrated below:

Delphi Example:

procedure TForm1.ReportSystem1Print(Sender: TObject);
var
  RavePage: TRavePage;
begin
  with Sender as TBaseReport do begin
    RaveProject1.ExecuteReport('LandscapeReport');

    RavePage := TRavePage(RaveProject1.ProjMan.FindRaveComponent('PortraitReport.MainPage',nil));
    Orientation := RavePage.Orientation;

    NewPage;
    PageNumOffset := 1 - CurrentPage;
    RaveProject1.ExecuteReport('PortraitReport');

    RavePage := TRavePage(RaveProject1.ProjMan.FindRaveComponent('LandscapeReport.MainPage',nil));
    Orientation := RavePage.Orientation;

    NewPage;
    PageNumOffset := 1 - CurrentPage;
    RaveProject1.ExecuteReport('LandscapeReport');

    RavePage := TRavePage(RaveProject1.ProjMan.FindRaveComponent('PortraitReport.MainPage',nil));
    Orientation := RavePage.Orientation;

    NewPage;
    PageNumOffset := 1 - CurrentPage;
    RaveProject1.ExecuteReport('PortraitReport');
  end;
end;

C++Builder Example:

void __fastcall TForm1::ReportSystem1Print(TObject *Sender)
{
  TRaveComponent* rc;
  TRavePage* RavePage;
  TRaveProjectManager* pm;

  pm = dynamic_cast(RaveProject1->ProjMan);

  TBaseReport* br = dynamic_cast(Sender);

  RaveProject1->ExecuteReport("LandscapeReport");

  rc = pm->FindRaveComponent("PortraitReport.MainPage",NULL);
  RavePage = dynamic_cast(rc);
  br->Orientation = RavePage->Orientation;

  br->NewPage();
  br->PageNumOffset = 1 - br->CurrentPage;
  RaveProject1->ExecuteReport("PortraitReport");

  rc = pm->FindRaveComponent("LandscapeReport.MainPage",NULL);
  RavePage = dynamic_cast(rc);
  br->Orientation = RavePage->Orientation;

  br->NewPage();
  br->PageNumOffset = 1 - br->CurrentPage;
  RaveProject1->ExecuteReport("LandscapeReport");

  rc = pm->FindRaveComponent("PortraitReport.MainPage",NULL);
  RavePage = dynamic_cast(rc);
  br->Orientation = RavePage->Orientation;

  br->NewPage();
  br->PageNumOffset = 1 - br->CurrentPage;
  RaveProject1->ExecuteReport("PortraitReport");
}