Multiple reports as single print job with changes in orientation

Category

Rave - General

Question

I have followed the example in the "Tip #41 Printing Multiple Rave Reports as a single print job." but the reports that I am printing have different page orientations and they aren't changing correctly. What do I need to do to get it to print with the correct page orientation?

Solution

Tip #41 works correctly as long as the Rave reports are all the same orientation as that which is set in the ReportSystem component. If you have reports that have different orientations then there is some additional work that needs to be done to get these to print correctly. The problem is that by the time you get into the OnPrint event of the ReportSystem the page orientatin has already been set to that of the ReportSystem orientation, which may not be what you want for the Rave report. This issue can be resolved through the use of the FindRaveComponent method, as explained in Tip #15, "Gaining Access To RAVE Components from Delphi/C++Builder." You need to use this method to get the orientation setting for the first page of the report that will be printed and then set the orientation before calling the NewPage method. So the first thing you would need to do is set the orientation property before calling the ReportSystem.Execute method:

Delphi Example:

procedure TForm1.Button1Click(Sender: TObject);
var
  RavePage: TRavePage;
begin
  RaveProject1.Open;
  // the LandscapeReport is the first Report that you want to print
  RavePage := TRavePage(RaveProject1.ProjMan.FindRaveComponent('LandscapeReport.MainPage',nil));
  ReportSystem1.SystemPrinter.Orientation := RavePage.Orientation;
  ReportSystem1.Execute;
end;

C++Builder Example:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TRavePage* RavePage;
  RaveProject1->Open();
  // the LandscapeReport is the first Report that you want to print
  RavePage = dynamic_cast(RaveProject1->ProjMan->FindRaveComponent("LandscapeReport.MainPage",NULL));
  ReportSystem1->SystemPrinter->Orientation = RavePage->Orientation;
  ReportSystem1->Execute();
}

You will also need to set the orientation before calling the NewPage event between reports:

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;
    RaveProject1.ExecuteReport('PortraitReport');

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

    NewPage;
    RaveProject1.ExecuteReport('LandscapeReport');

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

    NewPage;
    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();
  RaveProject1->ExecuteReport("PortraitReport");

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

  br->NewPage();
  RaveProject1->ExecuteReport("LandscapeReport");

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

  br->NewPage();
  RaveProject1->ExecuteReport("PortraitReport");
}