Components for Developers © 2000-2008, Two Pilots

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

 

How to create PDF file in Visual Basic.NET: "Hello, PDF!" example

Step by Step:

 

You can download the source code for the example project here: Visual Studio 2003 (43 Kb), Visual Studio 2005 (6 Kb).

This page contains a step-by-step tutorial that will teach you how to create PDF files from Visual Basic.NET application using PDF Creator Pilot library (version 3 and higher).

Take the following steps:

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

Go to New menu and click Project... to create a new project

Microsoft Development Environment main menu

You will see the New Project Wizard window. Select Windows Application in Visual Basic Projects:

New Project wizard

 

2) New project will be created. Visual Basic.NET will generate new project Project1 and will automatically open the main form of the newly generated project:

VB.NET project form

3) Now you should add a reference to PDF Creator Pilot to be able to use PDF library in VB.NET project. Select Project in the main menu and click Add Reference:

Project menu

Switch to COM tab and find PDF Creator Pilot in the list of available COM objects:

Add Reference dialog: list of available COM objects

Click the OK button to add a reference to PDF Creator Pilot.

4) Now you should implement the code that will generate "Hello, PDF!" PDF document. Double-click Form1 to create Form1_Load procedure:

VB.NET Application Form

The source code editing window will be opened:

Form1_Load procedure edit window

 

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

To generate a PDF document, you have to do the following:

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

Here is the source code:


Private Sub Form1_Load(ByVal sender As System.Object, 
                       ByVal e As System.EventArgs) Handles MyBase.Load

Dim PDF As PDFCreatorPilot3Lib.PDFDocument3

' create pdf library object

PDF = New PDFCreatorPilot3Lib.PDFDocument3

' initialize PDF Engine

PDF.StartEngine("demo@demo", "demo")

' set filename

PDF.FileName = "TestVB.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()

End Sub

This function will generate PDF document and save it as "TestVB.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

6) Press F5 to run the application (you can also use "Debug" | "Start" menu command).
Visual Basic.NET will run the application:

Debug menu

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:

Adobe Reader window

 

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