Hello World Visual Basic - SDK sample

Hello World VB sample is a simple Windows console application that prints one page with the "novaPDF says Hello World from VB" text to the novaPDF Printer. This sample can be the base of a more throughout application code that can benefit VB developers.

Note: To be able to use the samples you must install novaPDF SDK as samples work only with it. Download it here: nova PDF SDK.

It demonstrates the basic use of the INovaPDFOptions interface. The printing job is made with calls to the global Printer object defined by VB. It generates a "HelloWorld.pdf" file and opens it in the default PDF viewer.

Notice
If you print an existing document using "ShellExecute()" function or you want to handle printing events, you should check the VB Converter sample instead.

Source Code

' the novapiLib and novapiLibDemo packages must be added as a COM reference Const PRINTER_NAME As String = "novaPDF SDK 8" Const PROFILE_NAME As String = "Test VB" Const PROFILE_IS_PUBLIC As Long = 0 ' The main entry point for the application. Public Sub Main() On Error GoTo ErrorHandler: ' create the NovaPdfOptions object Dim pNova As New NovaPdfOptions80 Dim sOldActiveProfileID As String Dim sNewProfileID As String ' initialize the NovaPdfOptions object to use with a printer licensed for SDK pNova.Initialize2 (PRINTER_NAME) "" pNova.GetActiveProfile2 (sOldActiveProfileID) On Error Resume Next ' make new profile pNova.AddProfile2 PROFILE_NAME, PROFILE_IS_PUBLIC, sNewProfileID pNova.LoadProfile2 (sNewProfileID) ' and set some options ' uncomment the function calls for the options you wish to set and change the options in the Nova.vb unit '----------------- AddProfileOptions (pNova) AddDocumentInformation (pNova) AddViewerOptions (pNova) AddLinksOptions (pNova) AddAdvancedOptions (pNova) AddGraphicsOptions (pNova) AddEmbedFontsOptions (pNova) AddBookmarksDefinitions (pNova) AddSecurity (pNova) AddSaveOptions (pNova) AddAfterSaveActions (pNova) AddEmailOptions (pNova) AddWatermarkImage (pNova) AddWatermarkText (pNova) AddPageContentOptions (pNova) AddOverlayOptions (pNova) AddSignatureOptions (pNova) '----------------- 'save profile changes pNova.SaveProfile 'set as active profile for printer pNova.SetActiveProfile (sNewProfileID) ' Print a test page Dim myPrinter As Printer For Each myPrinter In Printers If myPrinter.DeviceName = PRINTER_NAME Then Set Printer = myPrinter Exit For End If Next Printer.FontName = "Arial" Printer.FontSize = 16 Printer.CurrentX = 20 Printer.CurrentY = 20 Printer.Print "novaPDF says Hello World from VB" Printer.EndDoc 'restore default profile If Len(sOldActiveProfileID) > 0 Then pNova.SetActiveProfile2 (sOldActiveProfileID) End If 'delete newly created profile pNova.DeleteProfile2 (sNewProfileID) Exit Sub ErrorHandler: Debug.Print (Err.Number & ":" & Err.Description) End Sub 

Comments


NEW: novaPDF 8.8.945