procedure SimpleImage(Path: String; D: TPDFDocument; APage: integer);
Var
P: TPDFPage;
FtTitle: integer;
IDX: Integer;
W, H: TPDFFloat;
begin
P := D.Pages[APage];
// create the fonts to be used (use one of the 14 Adobe PDF standard fonts)
FtTitle := D.AddFont('Helvetica');
{ Page title }
P.SetFont(FtTitle,23);
P.SetColor(clBlack, false);
P.WriteText(25, 20, 'Sample Image Support');
P.SetFont(FtTitle,10);
P.SetColor(clBlack, false);
IDX := D.Images.AddFromFile(Path, False);
W := PDFTomm(D.Images[IDX].Width);
H := PDFTomm(D.Images[IDX].Height);
P.DrawImage(20, 20, w, h, IDX);
end;
procedure SaveDocument(Path: String; D : TPDFDocument);
begin
if FileExists('C:\Users\User1\Desktop\TEST.pdf') then DeleteFile('C:\Users\User1\Desktop\TEST.pdf');
D.SaveToFile('C:\Users\User1\Desktop\TEST.pdf');
end;
function SetUpDocument: TPDFDocument;
var
P: TPDFPage;
S: TPDFSection;
i: integer;
lPageCount: integer;
begin
Result := TPDFDocument.Create(Nil);
Result.Infos.Title := Application.Title;
Result.Infos.Author := 'Graeme Geldenhuys';
Result.Infos.Producer := 'fpGUI Toolkit 1.4.1';
Result.Infos.ApplicationName := ApplicationName;
Result.Infos.CreationDate := Now;
Result.Infos.KeyWords:='fcl-pdf demo PDF support Free Pascal';
Result.StartDocument;
S := Result.Sections.AddSection; // we always need at least one section
lPageCount := 1;
for i := 1 to lPageCount do
begin
P := Result.Pages.AddPage;
P.PaperType := ptA4;
P.UnitOfMeasure := uomMillimeters;
S.AddPage(P); // Add the Page to the Section
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
D: TPDFDocument;
begin
D:= SetUpDocument;
SimpleImage('C:\Users\User1\Desktop\Unbenannt.PNG', D, 0);
SaveDocument(D);
end;