PDF printing from ReportSystem bypassing the setup dialog

Category

Code Based - General

Question

I want to print directly to PDF without displaying the setup dialog box. How do I do this using the TReportSystem component?

Solution

Starting with Rave 4.0 you have the ability to send reports to PDF. To accomplish this from a TReportSystem component, without any user intervention via the setup dialog, simply drop a TRPRenderPDF component on the form along with your TReportSystem component. Make sure the Active property is set to true. Then execute the following code in your Button/Menu OnClick event:

Delphi Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ReportSystem1.DefaultDest := rdFile;
  ReportSystem1.DoNativeOutput := false;
  ReportSystem1.RenderObject := RPRenderPDF1;
  ReportSystem1.OutputFileName := 'test1.pdf';
  ReportSystem1.SystemSetups := ReportSystem1.SystemSetups - [ssAllowSetup];
  ReportSystem1.Execute;
end;

C++Builder Example:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ReportSystem1->DefaultDest = rdFile;
  ReportSystem1->DoNativeOutput = false;
  ReportSystem1->RenderObject = RPRenderPDF1;
  ReportSystem1->OutputFileName = "test.pdf";
  ReportSystem1->SystemSetups = ReportSystem1->SystemSetups >> ssAllowSetup;
  ReportSystem1->Execute();
}

The report will be generated and saved to the "test.pdf" file bypassing the Setup Dialog box.

If you are doing a visual report you will want to assign the TRvSystem component to TRvProject.Engine property. Then when you are ready to execute the report call the ExecuteReport method of TRvProject instead of calling the execute method of the system component.

NOTE: If you wish to have the previous code work with a visually designed report, instead of one generated with a ReportSystem compoment, then all you need to do is assign the ReportSystem component to the Engine property of your RaveProject component. Then instead of calling the execute method of the ReportSystem component you would call the Execute/ExecuteReport method of the RaveProject component.

It should also be noted that as of version 5.0, the TReportSystem component has been renamed to TRvSystem and the TRaveProject component has been renamed to TRvProject.