unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  aspPDF_TLB, StdCtrls, ActiveX, OleCtrls, StdVCL, ComObj, ComCtrls,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Bevel1: TBevel;
    Button2: TButton;
    btnSaveFile: TButton;
    Bevel2: TBevel;
    btnSaveMem: TButton;
    GroupBox1: TGroupBox;
    btnAddGraph: TButton;
    edGraphX: TEdit;
    udGraphX: TUpDown;
    Label1: TLabel;
    Label2: TLabel;
    edGraphY: TEdit;
    udGraphY: TUpDown;
    GroupBox2: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    edTextX: TEdit;
    udTextX: TUpDown;
    edTextY: TEdit;
    udTextY: TUpDown;
    edTextFont: TEdit;
    Label5: TLabel;
    btnAddText: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    edText: TEdit;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnAddGraphClick(Sender: TObject);
    procedure btnAddTextClick(Sender: TObject);
    procedure btnSaveFileClick(Sender: TObject);
    procedure btnSaveMemClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  // Global pdf var
  pdf : IEASYPDF;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
begin
     Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     // Create the COM object
     PDF := CreateComObject(CLASS_EASYPDF) as IEASYPDF;
     // Init the memory
     // PDF.Create();
     //PDF.AddPage();
     //PDF.Debug := True;
     // Retrieve version
     edit1.Text := PDF.Version;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
     // Relase the memory on version 1.72 there is no need to call destroy
     //PDF.Destroy();
end;

procedure TForm1.btnAddGraphClick(Sender: TObject);
begin
   if OpenDialog1.execute then
   begin
     // Add a graphic
    PDF.AddGraphicPos( udGraphX.Position, udGraphY.Position, OpenDialog1.FileName );
    ShowMessage('Graphic added inside the PDF');
   end;
end;

procedure TForm1.btnAddTextClick(Sender: TObject);
begin
     // AddText at some position
   PDF.AddTextPos( udTextX.Position, udTextY.Position, edText.Text );
   ShowMessage('Text added inside the PDF');
end;

procedure TForm1.btnSaveFileClick(Sender: TObject);
begin
     // Save the file
   if SaveDialog1.Execute then
       PDF.Save( SaveDialog1.FileName );
end;

procedure TForm1.btnSaveMemClick(Sender: TObject);
var
  p : PChar;
begin
     // Memory save sample
  p := PDF.SaveStream;
  ShowMessage( p );
  if length(p) > 0 then
    if p[1] = 'P' then ShowMessage('Correct') else ShowMessage('PDF Failed');
end;

end.
