Fastreportexport is a library for export of Fast Report reports for multithreading and not GUI (Graphical User Interface) environments.
Implemented in Delphi language, it uses the fluent interface concept to guide the use of the library, designed to export reports in PDF, HTML, PNG formats, among others, as needed.
Environments
To use Fastreportexport you need to install the Fast Report component.
Using the BOSS (Dependency Manager for Delphi) it is possible to install the library automatically.
boss install github.com/antoniojmsjr/FastReportExport
If you choose to install manually, just add the following folders to your project, in Project> Options> Delphi Compiler> Target> All Configations> Search Path
..FastReportExportSource
Providers is an interface used by the library to export the reports that provides the TFRXCUSTOMEXPORFILTER class for configuration, and can be extended to implement other file formats.
| File | Provider | Tfrxcustomexportfilter |
|---|---|---|
| IFREXPORTPDF | TFRXPDFEXPORT | |
| Html | IFREXPORTHTML | Tfrxhtmlexort |
| PNG | IFREXPORTPNG | Tfrxpngexport |
| BMP | IFREXPORTBMP | Tfrxbmpexport |
| JPEG | IFREXPORTJPEG | TFRXJPEGEXPORT |
| CSV | IFREXPORTCSV | Tfrxcsvexport |
| RTF | IFREXPORTRTF | TFRXRTFEXPORT |
| XLS | IFREXPORTXLS | TFRXXLSEXPORT |
| XLSX | IFREXPORTXLSX | Tfrxxlsxexport |
| Docx | IFREXPORTDOCX | TFRXDOCXEXPORT |
Example
var
lFRExportPDF: IFRExportPDF;
lFRExportHTML: IFRExportHTML;
lFRExportPNG: IFRExportPNG;
begin
// PROVIDER PDF
lFRExportPDF := TFRExportProviderPDF.New;
lFRExportPDF.frxPDF.Subject := ' Samples Fast Report Export ' ;
lFRExportPDF.frxPDF.Author := ' Antônio José Medeiros Schneider ' ;
// PROVIDER HTML
lFRExportHTML := TFRExportProviderHTML.New;
// PROVIDER PNG
lFRExportPNG := TFRExportProviderPNG.New;
lFRExportPNG.frxPNG.JPEGQuality := 100 ;
end ;Datasets is an interface used by the library for communication with the database through the components:
| Class | Component |
|---|---|
| Chit | Native |
| TFRXDBDATASET | Fast report |
To exemplify the use of the library , IBGE locations API data was used to generate and export the report.
Export Example Archives: LocalitiesIBGE.pdf
Examples are available in the project folder:
..FastReportExportSamples
Example database
..FastReportExportSamplesDB
Example report
..FastReportExportSamplesReport
Example
uses FRExport, FRExport.Types, FRExport.Interfaces.Providers; var
lFRExportPDF: IFRExportPDF;
lFRExportHTML: IFRExportHTML;
lFRExportPNG: IFRExportPNG;
lFileStream: TFileStream;
lFileExport: string;
begin
// PROVIDER PDF
lFRExportPDF := TFRExportProviderPDF.New;
lFRExportPDF.frxPDF.Subject := ' Samples Fast Report Export ' ;
lFRExportPDF.frxPDF.Author := ' Antônio José Medeiros Schneider ' ;
// PROVIDER HTML
lFRExportHTML := TFRExportProviderHTML.New;
// PROVIDER PNG
lFRExportPNG := TFRExportProviderPNG.New;
lFRExportPNG.frxPNG.JPEGQuality := 100 ;
// CLASSE DE EXPORTAÇÃO
try
TFRExport.New.
DataSets.
SetDataSet(qryEstadosBrasil, ' EstadosBrasil ' ).
SetDataSet(frxdbMunicipioEstado).
SetDataSet(frxdbMunicipioRegiao).
SetDataSet(qryEstadoRegiao, ' EstadoRegiao ' ).
SetDataSet(qryMunicipios, ' Municipios ' ).
& End .
Providers.
SetProvider(lFRExportPDF).
SetProvider(lFRExportHTML).
SetProvider(lFRExportPNG).
& End .
Export .
SetFileReport(TUtils.PathAppFileReport). // LOCAL DO RELATÓRIO *.fr3
Report(procedure(pfrxReport: TfrxReport) // CONFIGURAÇÃO DO COMPONENTE DE RELATÓRIO DO FAST REPORT
var
lfrxComponent: TfrxComponent;
lfrxMemoView: TfrxMemoView absolute lfrxComponent;
begin
pfrxReport.ReportOptions.Author := ' Antônio José Medeiros Schneider ' ;
// PASSAGEM DE PARÂMETRO PARA O RELATÓRIO
lfrxComponent := pfrxReport.FindObject( ' mmoProcess ' );
if Assigned(lfrxComponent) then
begin
lfrxMemoView.Memo.Clear;
lfrxMemoView.Memo.Text := Format( ' Aplicativo de Exemplo: %s ' , [ ' VCL ' ]);
end ;
// VARIÁVEIS DO RELATÓRIO
pfrxReport.Variables.Variables[ ' DATA_HORA_IMPRESSAO ' ] := QuotedStr(DateTimeToStr(Now));
end ).
Execute; // EXECUTA O PROCESSO DE EXPORTAÇÃO DO RELATÓRIO
except
on E: Exception do
begin
if E is EFRExport then
ShowMessage(E.ToString)
else
ShowMessage(E.Message);
Exit;
end ;
end ;
// SALVAR PDF
if Assigned(lFRExportPDF.Stream) then
begin
lFileStream := nil ;
try
lFileExport := Format( ' %s%s ' , [TUtils.PathApp, ' LocalidadesIBGE.pdf ' ]);
lFileStream := TFileStream.Create(lFileExport, fmCreate);
lFileStream.CopyFrom(lFRExportPDF.Stream, 0 );
finally
FreeAndNil(lFileStream);
end ;
end ;
// SALVAR HTML
if Assigned(lFRExportHTML.Stream) then
begin
lFileStream := nil ;
try
lFileExport := Format( ' %s%s ' , [TUtils.PathApp, ' LocalidadesIBGE.html ' ]);
lFileStream := TFileStream.Create(lFileExport, fmCreate);
lFileStream.CopyFrom(lFRExportHTML.Stream, 0 );
finally
FreeAndNil(lFileStream);
end ;
end ;
// SALVAR PNG
if Assigned(lFRExportPNG.Stream) then
begin
lFileStream := nil ;
try
lFileExport := Format( ' %s%s ' , [TUtils.PathApp, ' LocalidadesIBGE.png ' ]);
lFileStream := TFileStream.Create(lFileExport, fmCreate);
lFileStream.CopyFrom(lFRExportPNG.Stream, 0 );
finally
FreeAndNil(lFileStream);
end ;
end ;
end ;Compiled example
Download: Demo.zip
Stress test for web applications using jmeter:
..FastReportExportSamplesJMeter
FastReportExport is free and open-source software licensed under the