unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
fppdf,fpjsonreport,jsonparser,
fpreportpdfexport
;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
uses
fpTTF
;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
filename : string;
destinationpdf : string;
rpt : TFPJSONReport;
RptExporter : TFPReportExportPDF;
begin
filename := Application.Location {$IFDEF DARWIN}+ '../../../' {$ENDIF} + 'REPORT' + System.DirectorySeparator + 'test.json';
destinationpdf := Application.Location {$IFDEF DARWIN}+ '../../../' {$ENDIF} + 'REPORT' + System.DirectorySeparator + 'abc.pdf';
try
try
if not fileexists(filename) then
ShowMessage('Report json not exists');
rpt := TFPJSONReport.Create(Self);
rpt.LoadFromFile(filename);
rpt.RunReport;
RptExporter := TFPReportExportPDF.Create(Self);
RptExporter.FileName := destinationpdf;
rpt.RenderReport(RptExporter);
RptExporter.SaveToFile;
finally
if Assigned(RptExporter) then
begin
RptExporter.Free;
RptExporter := nil
end;
if Assigned(rpt) then
begin
rpt.Free;
rpt := nil;
end;
if FileExists(destinationpdf) then
begin
ShowMessage('File exists: ' + destinationpdf);
end
else
begin
ShowMessage('File not exists: ' + destinationpdf);
end;
end;
except
on E: Exception do
begin
ShowMessage(E.Message);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{$IFDEF UNIX}
{$IFDEF DARWIN}
gTTFontCache.SearchPath.Add(ExtractFilePath(ParamStr(0))+'../../../../demos/fonts/');
gTTFontCache.SearchPath.Add(GetUserDir + 'Library/Fonts/');
gTTFontCache.SearchPath.Add('/Library/Fonts/');
gTTFontCache.SearchPath.Add('/System/Library/Fonts/');
gTTFontCache.SearchPath.Add('/System/Library/Fonts/');
{$ELSE}
gTTFontCache.SearchPath.Add(ExtractFilePath(ParamStr(0))+'../demos/fonts/');
gTTFontCache.SearchPath.Add(GetUserDir + '.fonts/');
gTTFontCache.SearchPath.Add('/usr/share/fonts/truetype/ubuntu-font-family/');
gTTFontCache.SearchPath.Add('/usr/share/fonts/truetype/dejavu/');
{$ENDIF}
{$ENDIF}
end;
end.