Unit MainForm;

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

Interface

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

Type
  TForm1 = Class(TForm)
    Image1: TImage;
    Procedure FormCreate(Sender: TObject);
  Private
    { Private declarations }
  Public
    { Public declarations }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.FormCreate(Sender: TObject);
Var
  PDF: TPDFlib;
  FontID, ImageID: Integer;
  Bitmap: TBitmap;
  Stream: TMemoryStream;
Begin
  PDF := TPDFlib.Create;
  Try
    Begin
      PDF.SetPageSize('A4');
      PDF.SetOrigin(1); // Set the origin to the top-left corner
      PDF.SetMeasurementUnits(1); // Set the measurement units to millimeters
      FontID := PDF.AddStandardFont(4); // Add a standard font, Helvetica

      PDF.SelectPage(1);
      PDF.SelectFont(FontID);
      PDF.SetTextColor(255, 0, 0);
      PDF.SetTextSize(16);
      PDF.DrawText(10, 10, 'Hello world.');
      ImageID := PDF.AddImageFromFile('Image1.bmp', 0);
      PDF.SelectImage(ImageID);
      PDF.DrawImage(5, 15, 280, 160);

      Stream := TMemoryStream.Create;
      PDF.RenderPageToStream(72, 1, 0, Stream);

      Stream.Seek(0, soFromBeginning);
      Bitmap := TBitmap.Create;
      Bitmap.LoadFromStream(Stream);
      Image1.Picture.Assign(Bitmap);
      Bitmap.Free;
      Stream.Free;
    End
  Finally
    PDF.Free;
  End;
End;

End.
