program pdfgui;
{$mode delphi}{$H+}
{$codepage UTF8}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, Interfaces, Forms, StdCtrls,
fppdf, ShellApi;
type
TMyForm = class(TForm)
public
MyButton: TButton;
procedure ButtonClick(ASender: TObject);
constructor Create(AOwner: TComponent); override;
end;
procedure TMyForm.ButtonClick(ASender:TObject);
var
FDoc: TPDFDocument;
FPage: TPDFPage;
FtBold: Integer;
Section: TPDFSection;
F: TFileStream;
FileName : String;
begin
FDoc := TPDFDocument.Create(Nil);
try
FDoc.Options := [poPageOriginAtTop, poUseImageTransparency, poMetadataEntry];
FDoc.StartDocument;
Section := FDoc.Sections.AddSection;
FPage := FDoc.Pages.AddPage;
FPage.PaperType := ptA4;
FPage.UnitOfMeasure := uomMillimeters;
Section.AddPage(FPage);
FtBold := FDoc.AddFont('Helvetica-Bold');
FPage.SetFont(FtBold, 16);
FPage.SetColor(clBlack, False);
FPage.WriteText(150, 150, 'æøå');
FileName := GetTempFileName('', 'invoice');
FileName := FileName + '.pdf';
F := TFileStream.Create(FileName,fmCreate);
try
FDoc.SaveToStream(F);
finally
F.Free;
end;
ShellExecute(0, 'open', PChar(FileName), Nil, PChar(ExtractFilePath(FileName)),1);
finally
FreeAndNil(FDoc);
end;
Close;
end;
constructor TMyForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Position := poScreenCenter;
Height := 400;
Width := 400;
VertScrollBar.Visible := False;
HorzScrollBar.Visible := False;
MyButton := TButton.Create(Self);
with MyButton do
begin
Height := 30;
Left := 100;
Top := 100;
Width := 100;
Caption := 'Close';
OnClick := ButtonClick;
Parent := Self;
end;
end;
var
MyForm : TMyForm;
begin
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TMyForm, MyForm);
Application.Run;
end.