Unit MainForm;

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

Interface

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

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

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.Button1Click(Sender: TObject);
Var
  StrMessage, StrFileName: String;
Begin
  With TPDFlib.Create Do
    Try

      // PDF output filename
      StrFileName := 'HelloWorld.pdf';

      // Draw the 'Hello World' text on the PDF page
      SetOrigin(1); // set top left mode
      DrawText(100, 100, 'Hello world from Delphi');

      // Attempt to save the file
      If (SaveToFile(StrFileName) = 1) Then
      Begin
        // Display message that the 'Hello Word' file has been written successfully
        StrMessage := StrFileName + ' written successfully';
        MessageBox(Handle, PChar(StrMessage), 'Information:', MB_OK or MB_ICONINFORMATION);
      End
      Else
      Begin
        // Display cannot write to file message
        StrMessage := 'Error, file could not be written.';
        MessageBox(Handle, PChar(StrMessage), 'Error:', MB_OK or MB_ICONSTOP);
      End;

    Finally
      Free;
    End;

End;

End.
