Hello World Visual Basic - SDK sample


Related Articles Add comment Email article Print article

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 package must be added as a COM reference
Const PRINTER_NAME As String = "novaPDF Pro v6"
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 NovaPdfOptions 

  ' initialize the NovaPdfOptions object
  ' if you have an application license for novaPDF SDK,
  ' pass both the registration name and the license key to the Initialize() function
  ' pNova.Initialize2 PRINTER_NAME, "<registration name>", "<license key>"
  pNova.Initialize2 PRINTER_NAME, "", "", ""
  ' get the active profile ...
  Dim activeProfile As String
  Dim bPublicProfile As Long 

  pNova.GetActiveProfile2 activeProfile, bPublicProfile
' and make a copy of it
  On Error Resume Next
  pNova.CopyProfile2 activeProfile, "Test VB", PROFILE_IS_PUBLIC
  If Err.Number <> 0 Then
      ' ignore profile exists error
      If NV_PROFILE_EXISTS = Err.Number Then
          Debug.Print "Profile Test VB already exists"
      Else
          Return
      End If
  End If

  On Error GoTo ErrorHandler:
  ' set the copy profile as active profile ...
  pNova.SetActiveProfile2 "Test VB", PROFILE_IS_PUBLIC
  ' and set some options
  pNova.SetOptionString2 NOVAPDF_INFO_SUBJECT, "VB Hello document", "", PROFILE_IS_PUBLIC 

  ' 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 

  ' Return to previous settings
  pNova.SetActiveProfile2 activeProfile, bPublicProfile
  pNova.DeleteProfile2 "Test VB", PROFILE_IS_PUBLIC
  Exit Sub
ErrorHandler:
  Debug.Print Err.Number & ":" & Err.Description
End Sub

Related articles

Comments