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
  x: Integer;
  StrMessage, StrFileName: String;
Begin
  With TPDFlib.Create Do
    Try
      // PDF output filename
      StrFileName := 'DrawShapes.pdf';

      // Display message containing the library version
      StrMessage := 'PDF library Draw Shapes sample' + chr(10) + 'Library version: ' + LibraryVersion + chr(10);

      // 100% red rectangle
      SetFillColor(1, 0, 0);
      DrawBox(100, 600, 400, 200, 1);

      // 20% green / 50% blue circles
      SetFillColor(0, 0.2, 0.5);
      DrawCircle(200, 500, 50, 1);
      DrawCircle(400, 500, 50, 1);

      // Yellow triangles
      SetFillColor(0.75, 0.75, 0);

      For x := 1 To 4 Do
      Begin
        StartPath(100 + x * 80, 200);
        AddLineToPath(70 + x * 80, 170);
        AddLineToPath(100 + x * 80, 140);
        AddLineToPath(130 + x * 80, 170);
        ClosePath;
        DrawPath(1);
      End;

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

    Finally
      Free;
    End;

End;

End.
