Unit MainForm;

{$I ..\..\..\Lib\PDFlibDefines.inc}

Interface

Uses
{$IFDEF XE2+}
  Winapi.Windows,
  System.Classes,
  System.SysUtils,
  Vcl.Controls,
  Vcl.StdCtrls,
  Vcl.Forms,
  Vcl.Dialogs,
{$ELSE}
  Windows,
  Classes,
  SysUtils,
  Controls,
  StdCtrls,
  Forms,
  Dialogs,
{$ENDIF}
  PDFlibrary;

Type
  TForm1 = Class(TForm)
    Button1: TButton;
    dlgSave: TSaveDialog;
    Procedure Button1Click(Sender: TObject);
  Private
    { Private declarations }
  Public
    { Public declarations }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.Button1Click(Sender: TObject);
Var
  PDFlib: TPDFlib;
  X: Integer;
  FontID: Integer;
  ImageID: Integer;
Begin
  dlgSave.InitialDir := ExtractFilePath(ParamStr(0));
  dlgSave.FileName := 'DemoLogo.pdf';
  If dlgSave.Execute Then
  Begin
    PDFlib := TPDFlib.Create;
    Try
      Begin
        // Set the paper size
        PDFlib.SetPageSize('A4');

        // Set the origin to the top-left corner
        PDFlib.SetOrigin(1);

        // Set the measurement units to millimeters
        PDFlib.SetMeasurementUnits(1);

        // Add a standard font
        FontID := PDFlib.AddStandardFont(4); // Helvetica

        // Add the logo from an image file
        PDFlib.CompressImages(1);
        ImageID := PDFlib.AddImageFromFile(ExtractFilePath(ParamStr(0)) + 'DemoLogo.png', 0);

        // Add 1 page, so there are a total of 2 pages in the document
        PDFlib.NewPages(1);

        For X := 1 To 2 Do
        Begin
          PDFlib.SelectPage(X);
          PDFlib.SelectImage(ImageID);
          PDFlib.DrawImage(50, 50, 23.1, 7.0);
          PDFlib.SelectFont(FontID);
          PDFlib.SetTextSize(16);
          PDFlib.SetTextColor(0, 0, 0);
        End;

        // Compress the contents of the file
        PDFlib.CompressContent;

        // Save the file
        PDFlib.SaveToFile(dlgSave.FileName);
      End
    Finally
      PDFlib.Free;
    End;
  End;
End;

End.
