Foxit Quick PDF Library

Hello world – your first PDF application with VB6

Before we starting this tutorial make sure that you’ve read through the previous tutorial which explains how to get up and running with VB6 and Foxit Quick PDF Library.

To begin with add a button to your Standard EXE form called Hello World. Then double-click on the button and in the code view in the VB6 IDE you should see the below.

Private Sub btnHelloWorld_Click()

End Sub

Lets start by declaring the variables that we will use in this tutorial. You will also need to include your license key here otherwise the library will not work.

Dim ClassName
Dim LicenseKey
Dim FileName

ClassName = "DebenuPDFLibraryAX01011.PDFLibrary"
LicenseKey = "..."
FileName = "C:\Hello-World-From-DQPL.pdf"

Dim DPL
Dim Result

Create an instance of the Foxit Quick PDF Library object.

Set DPL = CreateObject(ClassName)

Pass the license key to the UnlockKey function and then check to see if the license key is valid. The UnlockKey function returns the value 0 if the library could not be unlocked and returns the value 1 if the library could be unlocked. It’s always a good idea to validate your license key before using any of the other functions in the library.

Result = DPL.UnlockKey(LicenseKey)

If Result = 1 Then

Once the library has been unlocked we can then retrieve the library version using the LibraryVersion function and the LicenseInfo function.

MsgBox "Library version: " + DPL.LibraryVersion
MsgBox (DPL.LicenseInfo)

To demonstrate that the library was successfully unlocked we will also create a PDF and draw text onto it using the DrawText function.

Now don’t be confused if you look at the code and don’t see any function that is used to create a new document. When you initiate a new object of Foxit Quick PDF Library a blank document is automatically created, so you only need to use the NewDocument function if you want to create a second blank document.

	
Call DPL.DrawText(100, 500, "Hello world from Visual Basic 6")

Once we’ve drawn text on our new document we can save it to disk using the SaveToFile function.

If DPL.SaveToFile(FileName) = 1 Then
      MsgBox "File " + FileName + " written successfully."
   Else
      MsgBox "Error, file could not be written."
   End If
Else
   MsgBox "Invalid license key. Please set your license key by editing this file."
End If

After you’ve finished, don’t forget to clean up after yourself (i.e. free any memory that the script has used) by clearing the Foxit Quick PDF Library object.

Set DPL = Nothing

That’s all there is to it. In this sample you learnt how to register the license key, create a blank PDF, draw text on the PDF and then save the PDF to disk.

Now all you need to do is run your new application and click on the Hello World button to see this code in action. Good luck!

The full code for this sample has been provided below.

Full Sample Code

Private Sub btnHelloWorld_Click()

Dim ClassName
Dim LicenseKey
Dim FileName

ClassName = "DebenuPDFLibraryAX01011.PDFLibrary"
LicenseKey = "..."
FileName = "C:\Hello-World-From-DQPL.pdf"

Dim DPL
Dim Result

Set DPL = CreateObject(ClassName)
Result = DPL.UnlockKey(LicenseKey)

If Result = 1 Then

   MsgBox "Library version: " + DPL.LibraryVersion
   MsgBox (DPL.LicenseInfo)

   Call DPL.DrawText(100, 500, "Hello world from Visual Basic 6")

   If DPL.SaveToFile(FileName) = 1 Then
      MsgBox "File " + FileName + " written successfully."
   Else
      MsgBox "Error, file could not be written."
   End If
Else
   MsgBox "Invalid license key. Please set your license key by editing this file."
End If

Set DPL = Nothing

End Sub

Congratulations! You’ve created your first PDF application using VB6 and Foxit Quick PDF Library.

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: