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:

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:

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:

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:

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:

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

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

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:

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:

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.