mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-10 08:08:36 +02:00
* Demo how to create pdf from text file
git-svn-id: trunk@37425 -
This commit is contained in:
parent
a0fb85b690
commit
43867344cd
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -2784,6 +2784,8 @@ packages/fcl-report/demos/rptnestedgroups.pp svneol=native#text/plain
|
||||
packages/fcl-report/demos/rptshapes.pp svneol=native#text/plain
|
||||
packages/fcl-report/demos/rptsimplelist.pp svneol=native#text/plain
|
||||
packages/fcl-report/demos/rptttf.pp svneol=native#text/plain
|
||||
packages/fcl-report/demos/txt2pdf.lpi svneol=native#text/plain
|
||||
packages/fcl-report/demos/txt2pdf.pas svneol=native#text/plain
|
||||
packages/fcl-report/demos/udapp.pp svneol=native#text/plain
|
||||
packages/fcl-report/demos/webdemo.lpi svneol=native#text/plain
|
||||
packages/fcl-report/demos/webdemo.pp svneol=native#text/plain
|
||||
|
59
packages/fcl-report/demos/txt2pdf.lpi
Normal file
59
packages/fcl-report/demos/txt2pdf.lpi
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="10"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="Print File Application"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<CommandLineParams Value="txt2pdf.pas"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<Units Count="1">
|
||||
<Unit0>
|
||||
<Filename Value="txt2pdf.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="txt2pdf"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="../src"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
171
packages/fcl-report/demos/txt2pdf.pas
Normal file
171
packages/fcl-report/demos/txt2pdf.pas
Normal file
@ -0,0 +1,171 @@
|
||||
program txt2pdf;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, CustApp, fpreport, fpreportpdfexport, fpTTF,
|
||||
fpreportstreamer, fpjson, jsonparser;
|
||||
|
||||
type
|
||||
|
||||
{ TPrintApplication }
|
||||
|
||||
TPrintApplication = class(TCustomApplication)
|
||||
private
|
||||
FReport : TFPReport;
|
||||
FLines : TStringList;
|
||||
FData : TFPReportUserData;
|
||||
FLineIndex : Integer;
|
||||
procedure DoFirst(Sender: TObject);
|
||||
procedure DoGetEOF(Sender: TObject; var IsEOF: boolean);
|
||||
procedure DoGetNames(Sender: TObject; List: TStrings);
|
||||
procedure DoGetNext(Sender: TObject);
|
||||
procedure DoGetValue(Sender: TObject; const AValueName: string; var AValue: variant);
|
||||
protected
|
||||
procedure DoRun; override;
|
||||
public
|
||||
Constructor Create(AOwner : TComponent); override;
|
||||
Destructor destroy; override;
|
||||
end;
|
||||
|
||||
{ TPrintApplication }
|
||||
|
||||
procedure TPrintApplication.DoGetNames(Sender: TObject; List: TStrings);
|
||||
begin
|
||||
List.Add('Line');
|
||||
end;
|
||||
|
||||
procedure TPrintApplication.DoGetEOF(Sender: TObject; var IsEOF: boolean);
|
||||
begin
|
||||
isEOF:=FLineIndex>=FLines.Count;
|
||||
end;
|
||||
|
||||
procedure TPrintApplication.DoFirst(Sender: TObject);
|
||||
begin
|
||||
FLineIndex:=0;
|
||||
end;
|
||||
|
||||
procedure TPrintApplication.DoGetNext(Sender: TObject);
|
||||
begin
|
||||
Inc(FLineIndex);
|
||||
end;
|
||||
|
||||
procedure TPrintApplication.DoGetValue(Sender: TObject; const AValueName: string; var AValue: variant);
|
||||
begin
|
||||
Avalue:=FLines[FLineIndex];
|
||||
end;
|
||||
|
||||
procedure TPrintApplication.DoRun;
|
||||
|
||||
Var
|
||||
PG : TFPReportPage;
|
||||
PH : TFPReportPageHeaderBand;
|
||||
PF : TFPReportPageFooterBand;
|
||||
DB : TFPReportDataBand;
|
||||
M : TFPReportMemo;
|
||||
PDF : TFPReportExportPDF;
|
||||
Fnt : String;
|
||||
|
||||
begin
|
||||
Fnt:='DejaVuSans';
|
||||
Terminate;
|
||||
FLines.LoadFromFile(ParamStr(1));
|
||||
gTTFontCache.ReadStandardFonts;
|
||||
gTTFontCache.BuildFontCache;
|
||||
PaperManager.RegisterStandardSizes;
|
||||
// Page
|
||||
PG:=TFPReportPage.Create(FReport);
|
||||
PG.Data:=FData;
|
||||
PG.Orientation := poPortrait;
|
||||
PG.PageSize.PaperName := 'A4';
|
||||
PG.Margins.Left := 15;
|
||||
PG.Margins.Top := 15;
|
||||
PG.Margins.Right := 15;
|
||||
PG.Margins.Bottom := 15;
|
||||
// Page header
|
||||
PH:=TFPReportPageHeaderBand.Create(PG);
|
||||
PH.Layout.Height:=10; // 1 cm.
|
||||
M:=TFPReportMemo.Create(PH);
|
||||
M.Layout.Top:=1;
|
||||
M.Layout.Left:=1;
|
||||
M.Layout.Width:=120;
|
||||
M.Layout.Height:=7;
|
||||
M.Text:=ParamStr(1);
|
||||
M.Font.Name:=Fnt;
|
||||
M.Font.Size:=10;
|
||||
M:=TFPReportMemo.Create(PH);
|
||||
M.Layout.Top:=1;
|
||||
M.Layout.Left:=PG.Layout.Width-41;
|
||||
M.Layout.Width:=40;
|
||||
M.Layout.Height:=7;
|
||||
M.Text:='[Date]';
|
||||
M.Font.Name:=Fnt;
|
||||
M.Font.Size:=10;
|
||||
// Page footer
|
||||
PF:=TFPReportPageFooterBand.Create(PG);
|
||||
PF.Layout.Height:=10; // 1 cm.
|
||||
M:=TFPReportMemo.Create(PF);
|
||||
M.Layout.Top:=1;
|
||||
M.Layout.Left:=1;
|
||||
M.Layout.Width:=40;
|
||||
M.Layout.Height:=7;
|
||||
M.Text:='Page [PageNo]';
|
||||
M.Font.Name:=Fnt;
|
||||
M.Font.Size:=10;
|
||||
// Actual line
|
||||
DB:=TFPReportDataBand.Create(PG);
|
||||
DB.Data:=FData;
|
||||
DB.Layout.Height:=5; // 0.5 cm.
|
||||
DB.StretchMode:=smActualHeight;
|
||||
M:=TFPReportMemo.Create(DB);
|
||||
M.Layout.Top:=1;
|
||||
M.Layout.Left:=1;
|
||||
M.Layout.Width:=PG.Layout.Width-41;
|
||||
M.Layout.Height:=4;
|
||||
M.Text:='[Line]';
|
||||
M.StretchMode:=smActualHeight;
|
||||
M.Font.Name:=Fnt;
|
||||
M.Font.Size:=10;
|
||||
// Set up data
|
||||
FData.OnGetNames:=@DoGetNames;
|
||||
FData.OnNext:=@DoGetNext;
|
||||
FData.OnGetValue:=@DoGetValue;
|
||||
FData.OnGetEOF:=@DoGetEOF;
|
||||
FData.OnFirst:=@DoFirst;
|
||||
// Go !
|
||||
FReport.RunReport;
|
||||
PDF:=TFPReportExportPDF.Create(Self);
|
||||
try
|
||||
PDF.FileName:=ChangeFileExt(Paramstr(1),'.pdf');
|
||||
FReport.RenderReport(PDF);
|
||||
finally
|
||||
PDF.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TPrintApplication.Create(AOwner: TComponent);
|
||||
|
||||
begin
|
||||
Inherited;
|
||||
FReport:=TFPReport.Create(Self);
|
||||
FLines:=TStringList.Create;
|
||||
FData:=TFPReportUserData.Create(Self);
|
||||
end;
|
||||
|
||||
destructor TPrintApplication.destroy;
|
||||
begin
|
||||
FreeAndNil(FData);
|
||||
FreeAndNil(FLines);
|
||||
FreeAndNil(FReport);
|
||||
inherited destroy;
|
||||
end;
|
||||
|
||||
var
|
||||
Application: TPrintApplication;
|
||||
begin
|
||||
Application:=TPrintApplication.Create(nil);
|
||||
Application.Title:='Print File Application';
|
||||
Application.Run;
|
||||
Application.Free;
|
||||
end.
|
||||
|
@ -54,7 +54,7 @@
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="polygon;../units/$(TargetCPU)-$(TargetOS)"/>
|
||||
<OtherUnitFiles Value="polygon;../src"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
</CompilerOptions>
|
||||
|
Loading…
Reference in New Issue
Block a user