|
FastReport |
Top Previous Next |
|
For FastReport support please use the unit WPDF_FRep.
The uses clause should list: WPDF_FRep, WPPDFR1, WPPDFR2;
Now you can create the component TWPDF_FrPDFExport in code.
By creating the component in code, you do not need to compile the wPDF Package with Fastreport. This avoids dependencies between packages.
As soon as the component was created, the preview will show the PDF export option:
You need to attached a TWPDFPrinter component which will be used to produce the PDF output. In this object You can modify the PDF properties as needed. Here we placed the TWPDFPrinter on the form. The FrPDFExport component ist only created at the first call.
Important: If you need the component create the report prior to the export please create the compiler symbol PREPARE in the project options.
To export to a stream assign the stream directly to the TWPDF_FrPDFExport instance, property stream, not to WPPDFPrinter1.stream.
Example 1: Preview Report and let user print or save to PDF
var FrPDFExport : TWPDF_FrPDFExport;
procedure TForm1.Button1Click(Sender: TObject); begin if FrPDFExport = nil then FrPDFExport := TWPDF_FrPDFExport.Create(nil); FrPDFExport.PDFPrinter := WPPDFPrinter1; WPPDFPrinter1.Filename := 'c:\test.pdf';
frxReport1.ShowReport; end;
If you want to modify the properties before the PDF file is created you can use the OnShowDialog event.
Example 2: This code can be used to export directly without showing a dialog.
It creates the components dynamically so it is not required to install the TWPDF_FrPDFExport or the component TWPPDFPrinter.
uses ... WPDF_FRep, WPPDFR1, WPPDFR2;
var aPDFExport : TWPDF_FrPDFExport; begin aPDFExport := TWPDF_FrPDFExport.Create(nil); try // Use a instance of TWPPDFPrinter1 which was dropped on the form aPDFExport.PDFPrinter := WPPDFPrinter1; // Set a filename WPPDFPrinter1.Filename := 'c:\test_fr.pdf'; // Just for debugging WPPDFPrinter1.AutoLaunch := true;
// Prepare the report frxReport1.PrepareReport(true); // and export it using our filter frxReport1.Export( aPDFExport ); finally aPDFExport.Free; end; end;
Example 3: Create the PDF export and the filter in code (requires no packages):
// uses: WPPDFR1, WPPDFR2, WPDF_FRep;
procedure TForm1.Button2Click(Sender: TObject); var FrPDFExport1 : TWPDF_FrPDFExport; WPPDFPrinter1 : TWPPDFPrinter; begin FrPDFExport1 := TWPDF_FrPDFExport.Create(nil); WPPDFPrinter1 := TWPPDFPrinter.Create(nil); FrPDFExport1.PDFPrinter := WPPDFPrinter1;
WPPDFPrinter1.FileName := 'c:\test.pdf'; WPPDFPrinter1.AutoLaunch := true; try frxReport1.PrepareReport(true); frxReport1.Export(FrPDFExport1); finally FrPDFExport1.Free; WPPDFPrinter1.Free; end; end;
Note: wPDF supports FastReport Version 2 and higher. (If you still use V2 please disable the {$DEFINE FASTREP3} in unit WPDF_FRep).
|