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 Visual Basic: "Hello, PDF!" example

Step by Step

 

This page contains a step-by-step tutorial that will teach you how to create PDF files from Visual Basic application using PDF Creator Pilot library.

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

You will see the New Project Wizard:

Visual Basic New Project Wizard

2) Select Standard EXE project type and click Open to create new project.
Visual Basic will generate new project Project1 and will automatically open the main form of the newly generated project:

New VB project and new form

3) Now place a button that will launch PDF generation function. To place the button, just click CommandButton on the controls toolbar on the left:

Selecting command button on the controls panel

Now press your right mouse button and then drag the mouse in order to set a rectangle for the new control; release the mouse button to create the it. The new control will look like this:

Inserting new button control on the form

4) Visual Basic will create new button control in the Form1. Double-click this control to let Visual Basic create the click handler function in the project code:

Double-click button and code editor will appear

Visual Basic will create new function which will be launched every time a user clicks the button:

VB code editor window

5) Now you have to write the code that will generate your PDF file using PDF Creator Pilot.

To generate PDF document you have to do the following:

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

Here is the source code:


Private Sub Command1_Click()

' connect to library

Set PDF = CreateObject("PDFCreatorPilot3.PDFDocument3")

 ' initialize PDF Engine

 PDF.StartEngine "demo@demo", "demo"

 ' set PDF ouput filename

 PDF.FileName = "HelloPDF_VB.pdf"

 PDF.AutoLaunch = True ' auto-open generated pdf document

 ' start document generation

 PDF.BeginDoc

 ' draw"HELLO, PDF" message on the current PDF page

 PDF.PDFPAGE_SetActiveFont "Verdana", True, False, False, False, 14, 0

 PDF.PDFPAGE_TextOut 10, 20, 0, "HELLO, PDF!"

 ' finalize document generation

 PDF.EndDoc

 ' disconnect from library

 Set PDF = Nothing

 End Sub

This function will generate PDF document and save it as "HelloPDF_VB.PDF" file in the application's folder.

Hint: You can simply copy the source code from the snippet above and then paste it in the Visual Basic code editor as shown on the screenshot below:

VB code that create pdf

6) Press F5 to run the application (you can also use "Run" | "Start" menu command).
Visual Basic will run the application and you will see its main form:

Running VB project

7) Click "Command1" button. The application will generate "HelloPDF_VB.PDF" file.

If you have any PDF viewer (for example, Adobe Reader) installed on your computer, the library will launch it to open the generated PDF document:

PDF file 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