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 Debenu Quick PDF Library.
Step By Step
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 = "DebenuPDFLibraryAX01211.PDFLibrary"
LicenseKey = "..."
FileName = "C:\Hello-World-From-QPL.pdf"
Dim QP
Dim Result
Create an instance of the Debenu Quick PDF Library object.
Set QP = 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 = QP.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: " + QP.LibraryVersion
MsgBox (QP.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 Debenu 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 QP.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 QP.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 Debenu Quick PDF Library object.
Set QP = 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 = "DebenuPDFLibraryAX01211.PDFLibrary"
LicenseKey = "..."
FileName = "C:\Hello-World-From-QPL.pdf"
Dim QP
Dim Result
Set QP = CreateObject(ClassName)
Result = QP.UnlockKey(LicenseKey)
If Result = 1 Then
MsgBox "Library version: " + QP.LibraryVersion
MsgBox (QP.LicenseInfo) Call QP.DrawText(100, 500, "Hello world from Visual Basic 6")
If QP.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 QP = Nothing
End Sub
Congratulations! You've created your first PDF application using VB6 and Debenu Quick PDF Library.
Let us know what you think
We provide code samples to give you a good idea of how to use the Debenu Quick PDF Library with the language of your choice. There is a steadily growing collection of code samples to get you started, but if you suggestions for other samples you would like to see, please let us know.