procedure ExportCsvAsPdf(CsvSource,PdfFileName : string);
Var TempFile : string;
rpt: TFPReport;
lDataSet : TCSVDataset;
lReportData: TFPReportDatasetData;
p: TFPReportPage;
TitleBand: TFPReportTitleBand;
Memo: TFPReportMemo;
DataBand: TFPReportDataBand;
Image: TFPReportImage;
RptExporter: TFPReportExporter;
X : integer;
begin
PaperManager.RegisterStandardSizes;
rpt:=TFPReport.Create(nil);
rpt.Title := 'FPReport Demo 8 - Datasets';
try
// ***** Providing data to the report *****
lReportData := TFPReportDatasetData.Create(nil);
lDataSet := TCSVDataset.Create(nil);
lDataSet.FileName:=CsvSource;
lReportData.DataSet := lDataSet;
// ***** Adding a page *****
p := TFPReportPage.Create(rpt);
p.Orientation := poPortrait;
p.PageSize.PaperName := 'A4';
{ page margins }
p.Margins.Left := 30;
p.Margins.Top := 20;
p.Margins.Right := 30;
p.Margins.Bottom := 20;
{ page's default font }
p.Font.Name := 'Calibri'; // this is the PostScript name of the TTF font
{ assign the data for the page data loop }
p.Data := lReportData;
// ***** Adding bands to a page *****
TitleBand := TFPReportTitleBand.Create(p);
TitleBand.Layout.Height := 40;
// TitleBand.Frame.Shape := fsRectangle;
// TitleBand.Frame.BackgroundColor := clYellow;
Memo := TFPReportMemo.Create(TitleBand);
Memo.Layout.Left := 5;
Memo.Layout.Top := 0;
Memo.Layout.Width := 140;
Memo.Layout.Height := 15;
Memo.Text := 'Dataset Demo';
Memo.TextAlignment.Vertical := tlCenter;
Memo.TextAlignment.Horizontal := taCentered;
Memo.UseParentFont := False;
Memo.Font.Color := TFPReportColor($000080);
Memo.Font.Size := 24;
// ***** The loop data *****
DataBand := TFPReportDataBand.Create(p);
DataBand.Layout.Height := 30;
DataBand.Data:= lReportData;
// DataBand.Frame.Shape := fsRectangle;
// DataBand.Frame.BackgroundColor := clCream;
Memo := TFPReportMemo.Create(DataBand);
Memo.Layout.Left := 30;
Memo.Layout.Top := 0;
Memo.Layout.Width := 50;
Memo.Layout.Height := 5;
Memo.Text := 'Item_Type: [Item_Type]';
// ***** Running the report *****
{ specify what directories should be used to find TrueType fonts }
gTTFontCache.ReadStandardFonts;
gTTFontCache.BuildFontCache;
// for X := 0 to gTTFontCache.Count-1 do
// Writeln(gTTFontCache.Items[X].PostScriptName);
rpt.RunReport;
// if Assigned(RptExporter) then
// FreeAndNil(RptExporter);
RptExporter := TFPReportExportPDF.Create(nil);
RptExporter.SetFileName(PdfFileName);
rpt.RenderReport(RptExporter);
finally
// Freeing all objects we used
FreeAndNil(RptExporter);
FreeAndNil(rpt);
FreeAndNil(lReportData);
FreeAndNil(lDataset);
end;
end;