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:

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

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

Press OK and confirm it by pressing Yes:

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

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

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

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

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):

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:

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:
- initialize PDF Creator Pilot PDF engine;
- set the file name for your PDF document;
- draw "Hello, PDF!" message on the PDF page;
- 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:

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:

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:
- Visual Basic Script (VBScript)
- Visual Basic (VB)
- Visual Basic.NET (VB.NET)
- C Sharp (C#)
- Active Server Pages (ASP)
- Active Server Pages for .NET (ASP.NET)
- Delphi
- Visual C++
See also:
- PDF documents and PDF files. Introduction and short description
- PDF Creator Pilot technology
- PDF Creator Pilot FAQ
If you have questions related to PDF Creator Pilot, contact us via our online support form.