5
How to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to create PDF with 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... ":

How to create PDF file with Delphi - Two · PDF fileHow to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to createPDFwith Delphi using

  • Upload
    vonhi

  • View
    271

  • Download
    0

Embed Size (px)

Citation preview

Page 1: How to create PDF file with Delphi - Two · PDF fileHow to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to createPDFwith Delphi using

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

This page contains step by step tutorial how to createPDFwith Delphi using PDF Creator Pilot library.

1)InstallPDF Creator Pilotlibrary on your computer and runDelphi.

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 selectPDF Creator Pilotin the libraries list and press "Install...":

Page 2: How to create PDF file with Delphi - Two · PDF fileHow to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to createPDFwith Delphi using

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

PressOKand confirm it by pressingYes:

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

Page 3: How to create PDF file with Delphi - Two · PDF fileHow to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to createPDFwith Delphi using

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

5)New application project will be created. Go to components panel and clickButtoncontrol icon on the palette:

Then click on the form and Delphi will create and place theButton1object on the form as shown on the screenshot below:

6)Now selectActiveXpage on the comonents palette, selectpiPDFDocumentcomponent:(this component was generated automatically for PDF Creator Pilot on steps 2 and 3).

Page 4: How to create PDF file with Delphi - Two · PDF fileHow to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to createPDFwith Delphi using

Then click on the form and Delphi will create and placepiPDFDocument1object on the form. This object will control PDF CreatorPilot library.

7)Double-click theButton1button on the form and code editor window will appear:

8)Code snippet for theTForm1.Button1Clickprocedure is shown below. This code is quite simple and its algorithm is quite simpletoo. To create PDF file you have to do the following things:

1. initialize PDF Creator Pilot PDF engine;

2. set the filename for the PDF file;

3. draw "Hello, PDF!" message on the PDF document;

4. disconnect from the library.

procedureTForm1.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_BeginText;

piPDFDocument1.PDFPAGE_SetActiveFont(’Verdana’, True, False, False, False, 14,

charsetANSI_CHARSET);

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

piPDFDocument1.PDFPAGE_EndText;

// finalize document generation

piPDFDocument1.EndDoc;

end;

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

Page 5: How to create PDF file with Delphi - Two · PDF fileHow to create PDF file with Delphi: "Hello, PDF!" example This page contains step by step tutorial how to createPDFwith Delphi using

9)Now clickF9to compile and run application. Delphi will runProject1andForm1will appear. Click theButton1and application willcreate "Hello, PDF!" document.

If you have PDF viewer installed (for example,Adobe Acrobat Reader), then application will openHelloPDF_DELPHI.PDFfile as itshown below:

You can find the source code of this example in the"\Examples\Delphi\"sub-folder.