Recent

Author Topic: fpReport and CSV file  (Read 162 times)

JohnnieK

  • New Member
  • *
  • Posts: 29
fpReport and CSV file
« on: November 29, 2024, 01:12:04 pm »
Hi

I am trying to build a simple csv file to pdf converter using fpreport. I took the sample and modified it as below. When I run it, the pdf just has the title page. I am not sure what I am missing.
Code: Pascal  [Select][+][-]
  1. procedure ExportCsvAsPdf(CsvSource,PdfFileName : string);
  2.  Var TempFile : string;
  3.      rpt: TFPReport;
  4.      lDataSet : TCSVDataset;
  5.      lReportData: TFPReportDatasetData;
  6.      p: TFPReportPage;
  7.      TitleBand: TFPReportTitleBand;
  8.      Memo: TFPReportMemo;
  9.      DataBand: TFPReportDataBand;
  10.      Image: TFPReportImage;
  11.      RptExporter: TFPReportExporter;
  12.      X : integer;
  13.    begin
  14.     PaperManager.RegisterStandardSizes;
  15.     rpt:=TFPReport.Create(nil);
  16.     rpt.Title := 'FPReport Demo 8 - Datasets';
  17.     try
  18.       // ***** Providing data to the report *****
  19.       lReportData := TFPReportDatasetData.Create(nil);
  20.       lDataSet := TCSVDataset.Create(nil);
  21.       lDataSet.FileName:=CsvSource;
  22.       lReportData.DataSet := lDataSet;
  23.       // ***** Adding a page *****
  24.       p := TFPReportPage.Create(rpt);
  25.       p.Orientation := poPortrait;
  26.       p.PageSize.PaperName := 'A4';
  27.  
  28.       { page margins }
  29.       p.Margins.Left := 30;
  30.       p.Margins.Top := 20;
  31.       p.Margins.Right := 30;
  32.       p.Margins.Bottom := 20;
  33.  
  34.       { page's default font }
  35.       p.Font.Name := 'Calibri';  // this is the PostScript name of the TTF font
  36.  
  37.       { assign the data for the page data loop }
  38.       p.Data := lReportData;
  39.  
  40.       // ***** Adding bands to a page *****
  41.       TitleBand := TFPReportTitleBand.Create(p);
  42.       TitleBand.Layout.Height := 40;
  43.   //    TitleBand.Frame.Shape := fsRectangle;
  44.   //    TitleBand.Frame.BackgroundColor := clYellow;
  45.  
  46.       Memo := TFPReportMemo.Create(TitleBand);
  47.       Memo.Layout.Left := 5;
  48.       Memo.Layout.Top := 0;
  49.       Memo.Layout.Width := 140;
  50.       Memo.Layout.Height := 15;
  51.  
  52.       Memo.Text := 'Dataset Demo';
  53.       Memo.TextAlignment.Vertical := tlCenter;
  54.       Memo.TextAlignment.Horizontal := taCentered;
  55.  
  56.       Memo.UseParentFont := False;
  57.       Memo.Font.Color := TFPReportColor($000080);
  58.       Memo.Font.Size := 24;
  59.  
  60.       // ***** The loop data *****
  61.       DataBand := TFPReportDataBand.Create(p);
  62.       DataBand.Layout.Height := 30;
  63.       DataBand.Data:= lReportData;
  64.   //    DataBand.Frame.Shape := fsRectangle;
  65.   //    DataBand.Frame.BackgroundColor := clCream;
  66.  
  67.       Memo := TFPReportMemo.Create(DataBand);
  68.       Memo.Layout.Left := 30;
  69.       Memo.Layout.Top := 0;
  70.       Memo.Layout.Width := 50;
  71.       Memo.Layout.Height := 5;
  72.       Memo.Text := 'Item_Type: [Item_Type]';
  73.  
  74.  
  75.       // ***** Running the report *****
  76.       { specify what directories should be used to find TrueType fonts }
  77.       gTTFontCache.ReadStandardFonts;
  78.       gTTFontCache.BuildFontCache;
  79. //      for X := 0 to gTTFontCache.Count-1 do
  80. //       Writeln(gTTFontCache.Items[X].PostScriptName);
  81.  
  82.       rpt.RunReport;
  83.  
  84. //      if Assigned(RptExporter) then
  85. //        FreeAndNil(RptExporter);
  86.       RptExporter := TFPReportExportPDF.Create(nil);
  87.       RptExporter.SetFileName(PdfFileName);
  88.       rpt.RenderReport(RptExporter);
  89.     finally
  90.       // Freeing all objects we used
  91.       FreeAndNil(RptExporter);
  92.       FreeAndNil(rpt);
  93.       FreeAndNil(lReportData);
  94.       FreeAndNil(lDataset);
  95.     end;
  96.    end;

Any help would be appreciated as I have read all the docs that are available. Thanx

 

TinyPortal © 2005-2018