Components for Developers © 2000-2008, Two Pilots

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF Add-on History In the Lab

PDF version of this article is available.
Click here to download.

How to create PDF file in Delphi: "Hello, PDF!" example

Step by Step

 

This page contains a step-by-step tutorial that will teach you how to create PDFfiles from Delphi using PDF Creator Pilot library.

1) Install PDF Creator Pilot library on your computer and run Delphi.

2) First, you have to add PDF Creator Pilot library as a component to the component palette.
Select "Project" | "Import Type Library" command as shown below:

Project menu. Import Type Library command

3) Import dialog will appear. Find and select PDF Creator Pilot in the libraries list and press "Install...":

Import Type Library dialog

Delphi will suggest you to install PDF Creator Pilot into the user component package and Install dialog will appear:

Component installation dialog

Press OK and confirm it by pressing Yes:

Confirmation message

Dephi will recompile user components package and Pilot Creator PDF will be installed as TpiPDFDocument component on the "ActiveX" components page.

Information message

4) Now create a new application. Go to the "File" menu and select "New Application" command:

New application command

5) A new application project will be created. Go to components panel and click Button control icon on the palette:

Standard controls palette

Then click inside the form and Delphi will create and place the Button1 object into the form as shown on the screenshot below:

Button on the form

6) Now select ActiveX page on the comonents palette, select piPDFDocument component (this component was generated automatically for PDF Creator Pilot during steps 2 and 3):

piPDFDocument component on the ActiveX components page

Then click inside the form and Delphi will create and place piPDFDocument1 object there. This object will control PDF Creator Pilot library.

7) Double-click the Button1 button inside the form and code editor window will appear:

Code editor

8) Code snippet for the TForm1.Button1Click procedure is shown below. This code is quite simple and its algorithm is quite simple too. To create PDF file, you have to do the following things:

  1. initialize PDF Creator Pilot PDF engine;
  2. set the file name for your PDF document;
  3. draw "Hello, PDF!" message on the PDF page;
  4. disconnect from the library.

procedure TForm1.Button1Click(Sender: TObject);

begin

  // initialize PDF Engine
  piPDFDocument1.StartEngine('demo@demo', 'demo');

  // set PDF output filename
  piPDFDocument1.FileName := 'HelloPDF_DELPHI.pdf';

  // set option to auto-open generated pdf document
  piPDFDocument1.AutoLaunch := True;

  // start document generation
  piPDFDocument1.BeginDoc;

  // draw 'HELLO, PDF' message on the current PDF page
  piPDFDocument1.PDFPAGE_SetActiveFont('Verdana', True, False, False, False, 
                                                  14, charsetANSI_CHARSET);

  piPDFDocument1.PDFPAGE_TextOut(10, 20, 0, 'HELLO, PDF!');

  // finalize document generation
  piPDFDocument1.EndDoc;

end;

This code will create "HelloPDF_Delphi.PDF"PDF file. You can simply copy this listed code to the clipboard and paste it into the Delphi code editor as it is shown below:

Copy & paste code

9) Now click F9 to compile and run the application. Delphi will run Project1 and Form1 will appear. Click the Button1 and the application will create "Hello, PDF!" document.

If you have PDF viewer installed (for example, Adobe Reader), then the application will open HelloPDF_DELPHI.PDF file as shown on the screenshot below:

Hello, PDF! document in the Adobe Reader window

You can download the source code for the described "Hello, PDF!" project here (23 KB).

 

PDF Creator Pilot can be used with different languages to generate PDF files. See "Hello, PDF" example for:

See also:

 

If you have questions related to PDF Creator Pilot, contact us via our online support form.

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF Add-on History In the Lab

 

 

PDF Library | Virtual Printer | Converters to PDF

Support | Blog | Forum | Contacts | Site map

© 2000-2008, Two Pilots