Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library
Tutorials > Delphi > Hello world — your first PDF application with Delphi
Previous | Next

Hello world — your first PDF application with Delphi

Before we starting this tutorial make sure that you've read through the previous tutorial which explains how to get up and running with delphi and Debenu Quick PDF Library.

Step By Step

To begin add a TButton and a TLabel component onto your form. Also, add Debenu Quick PDF Library's unit (DebenuPDFLibrary01211) to the uses clause of your form unit:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DebenuPDFLibrary01211;

Double-click the TButton to add an OnClick event, and fill in the following event code.

procedure TForm1.Button1Click(Sender: TObject);

Now we'll declare the variables that we will use in this tutorial.

var
  PDFLibrary: TDebenuPDFLibrary01211;
  UnlockResult: Integer;

Create an instance of Debenu Quick PDF Library.

begin
  PDFLibrary := TDebenuPDFLibrary01211.Create;

Before you can successfully make calls to functions in the PDF API you will need to unlock the library by calling the UnlockKey function with your license key. You can also check the type of license that you're using by calling the LicenseInfo function.

  try
    UnlockResult := PDFLibrary.UnlockKey('you_license_key');
    Label1.Caption := PDFLibrary.LicenseInfo;
    if UnlockResult = 1 then
    begin

When an instance of Debenu Quick PDF Library is initiated a blank document is automatically created and loaded into memory, so it's not necessary to create a new document before starting to call drawing commands.

So, lets draw some text onto the PDF file using the DrawText function and then save the file to disk using the SaveToFile function. Change the path in the SaveToFile function to an existing folder on your computer.

      PDFLibrary.DrawText(100, 500, 'Hello from Delphi');
      PDFLibrary.SaveToFile('C:\Docs\HelloFromDelphi.pdf');
    end else

Display an error message if the library could not be unlocked.

    begin
      ShowMessage('Invalid license key');
    end;

Close this instance of Debenu Quick PDF Library once you've finished using it.

  finally
    PDFLibrary.Free;
  end;
end;

That's all there is to it. In this sample you learnt how to register the license key, create a blank PDF, draw text on the PDF and then save the PDF to disk.

Now all you need to do is run your new application and click on the button to see this code in action. Good luck!

The full code for this sample has been provided below.

Full Sample Code

uses    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DebenuPDFLibrary01211;

procedure TForm1.Button1Click(Sender: TObject);
var
  PDFLibrary: TDebenuPDFLibrary01211;
  UnlockResult: Integer;
begin
  PDFLibrary := TDebenuPDFLibrary01211.Create;
  try
    UnlockResult := PDFLibrary.UnlockKey('you_license_key');
    Label1.Caption := PDFLibrary.LicenseInfo;
    if UnlockResult = 1 then
    begin
      PDFLibrary.DrawText(100, 500, 'Hello from Delphi');
      PDFLibrary.SaveToFile('C:\Docs\HelloFromDelphi.pdf');
    end else
    begin
      ShowMessage('Invalid license key');
    end;
  finally
    PDFLibrary.Free;
  end;
end;

Congratulations! You've created your first PDF application using Delphi and Debenu Quick PDF Library.

Let us know what you think

We provide code samples to give you a good idea of how to use the Debenu Quick PDF Library with the language of your choice. There is a steadily growing collection of code samples to get you started, but if you suggestions for other samples you would like to see, please let us know.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum