We help IT Professionals succeed at work.

Crystal Reports 11 VCL Delphi 2009/XE2 ...

trevsoft
trevsoft asked
on
Hi Experts,

Im trying to export/convert an crystal reports file to a pdf file on the fly, but i seem to be having issues trying to get it work.

Does any one have some sample code to do this.

I dont want the Crystal Reports Viewer being displayed, i just want to select the report, pass the required parameters and export the output to a PDF file.

Thank you in advance. :)


Trevor
Comment
Watch Question

Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Are you able to disply a report in the viewer?
What code do you use for that?

mlmcc

Author

Commented:
Hi mlmcc,

Yes i can display the report fine. I have worked out, what im trying to do now is not display the report but export it to pdf as a file.



Trevor
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
What code do you use for that.

I use VB6 and I only have to changea line or 2 to get it to export.

mlmcc

Author

Commented:
Hi mlmcc,

This is the code i pass to execute the report.

procedure TForm1.Button2Click(Sender: TObject);
var
  i : Integer;
begin
  with Crpe do
    begin
      ReportName := 'report.rpt';

      DiscardSavedData;

      for i := 0 to ParamFields.Count - 1 do
        begin
          if ParamFields[ i ].Name= 'startdate' then
            ParamFields[ i ].CurrentValue := FormatDateTime('yyyy,mm,dd', wwDBDateTimePicker1.Date);
          if ParamFields[ i ].Name= 'enddate' then
            ParamFields[ i ].CurrentValue := FormatDateTime('yyyy,mm,dd', wwDBDateTimePicker2.Date);
        end;

      WindowState := wsMaximized;

      Execute;  // Execute the Report.
    end;
end;

I changed the output parameter to 'toExport' but not sure where to specify the export to PDF, whether its done in code or at design time.


Trevor