Hello World VBNet - SDK sample

Download Sample
Download size: 38.4KB
[Format: ZIP]
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.

Hello World VBNet sample is a simple Windows console application that prints one page with the "novaPDF says Hello World from VB.Net" text to the novaPDF Printer. It demonstrates the basic use of the INovaPDFOptions interface.
The printing job is made using the package "System.Drawing.Printing" Basically the sample determines the active profile, makes a copy of it into a profile called "Test VBNet", sets the new profile as active, sets the subject of the generated PDF document, prints a page, and restores original printer settings. The location of the generated document depends on whatever the settings are for the current active profile.

Notice
Because of the specific exception based error handling in .NET, all calls to methods in the INovaPDFOptions interface must be nested within a try–catch block. Consider for example that we want to add a profile called "test", but the profile "test" already exists. Then the call pNova.AddProfile("test") will throw an "System.Runtime.InteropServices.COMException". with the ErrorCode property set to NV_PROFILE_EXISTS (0xD5DA0006).

Source Code

Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
' the novapiLib package must be added as a COM reference
Imports novapiLib

Module Module1
  '    <summary>
  '    The    main entry point for the application.
  '    </summary>
  Const PRINTER_NAME As String = "novaPDF Pro v5"
  Const PROFILE_NAME As String = "Test VBNet"
  Const PROFILE_IS_PUBLIC As Integer = 0
  Const NOVAPDF_INFO_SUBJECT As String = "Document Subject"
  Const NV_PROFILE_EXISTS As Long = -707133434 

  Sub Main()
      Try
          ' create the NovaPdfOptions object
          Dim pNova As NovaPdfOptions
          pNova = 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.Initialize(PRINTER_NAME, "<registration name>", "<license key>");
          pNova.Initialize(PRINTER_NAME, "", "", "")
          ' get the active profile ...
          Dim activeProfile As String
           Dim nActivePublic As Integer
          pNova.GetActiveProfile(activeProfile, nActivePublic)
          Try
              ' and make    a copy of it
              pNova.CopyProfile(activeProfile, PROFILE_NAME, PROFILE_IS_PUBLIC)
          Catch e As System.Runtime.InteropServices.COMException
              ' ignore profile exists error
              If (NV_PROFILE_EXISTS = e.ErrorCode) Then
                  System.Console.WriteLine("Profile already exists")
              Else
                  ' more    serious    error, propagate it
                  Throw e
              End If
          End Try
          ' set the copy    profile    as active profile ...
          pNova.SetActiveProfile(PROFILE_NAME, PROFILE_IS_PUBLIC)
          ' and set some    options
          pNova.SetOptionString(NOVAPDF_INFO_SUBJECT, "VB.Net Hello document", PROFILE_NAME, PROFILE_IS_PUBLIC)
          ' print a test    page, using    the    previously set active profile settings
          Dim pd As PrintDocument = New PrintDocument
          pd.PrinterSettings.PrinterName = PRINTER_NAME
          AddHandler pd.PrintPage, AddressOf PrintPageFunction
          pd.Print()
          pNova.SetActiveProfile(activeProfile, nActivePublic)
          pNova.DeleteProfile(PROFILE_NAME, PROFILE_IS_PUBLIC)
      Catch e As System.Runtime.InteropServices.COMException
          MessageBox.Show(e.Message)
      Catch e As Exception
          MessageBox.Show(e.Message)
      End Try
  End Sub 

  ' and finally the function that actually prints the page
  Private Sub PrintPageFunction(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
      Dim str As String = "novaPDF says Hello World from VB.Net"
      Dim font As Font = New Font("Arial", 16)
      Dim brush As Brush = New SolidBrush(Color.Black)
      ev.Graphics.DrawString(Str, font, brush, 20.0!, 20.0!)
      ev.HasMorePages = False
  End Sub 

End Module

© 2002-2008 Softland. All Rights Reserved.
PDF Creator novaPDF
Create PDF for your paperless office
home Home   contact usContact us   partnershipsPartnerships   bookmarkBookmark   Site updated: 14-August-2008
Downloads Download Now

Download, install and use novaPDF. Latest version: 5.4 build 270

Download PDF creator
promotionsSpecial Offers

Current discounts:
- up to 25% for Desktop Editions
- up to 25% for Server Editions
- 20% Academic Discount
- up to 16% for Developer Tools

buyBuy Now
Professional edition $39.95
(Save $10)
Standard edition $29.95
(Save $10)
Lite edition $19.95
(Save $5)
Buy Now
newsLatest News

novaPDF 5.4 released
February 11, 2008

What’s new (read more):
 » Added Copy Text/Image Watermarks dialog
 » Added "Lookup Address" option when sending emails
 » Corrected rotated and vertical texts conversion
 » Corrected conversion from WordArt, MS Word backgrounds and MS Visio drawings
 » Uninstaller deletes now the driver files

sdkDeveloper Tools

novaPDF SDK is a software development toolkit that can be used by software developers and programmers to add the ability to create PDF files in their applications.
novaPDF OEM is a PDF solution that programmers can use to generate PDF files that will be post-processed by their applications. […]

Reviews & User QuotesPDF Creator Reviews
"novaPDF is a really neat tool. Basically, it’s a PDF printer driver that prints to a PDF file instead of paper.
See more reviews about nova PDF
[…] novaPDF is a great product that works without forcing the user to configure anything. The convenience alone is worth the money." […]
Jason Pullara, Editor
Currently supported languagesLanguages

News:
- Norwegian language added.

Help us translate novaPDF and we will give you licenses for novaPDF Professional and mention you on the Languages page. […]

awardsAwards

novaPDF received the Editor’s Pick from Soft32, a major download site:

PDF creator reviews

See the Awards page for more ratings.

NewsletterKnowledgebase articles

Latest articles on how to:
 » Create PDF files
 » Convert JPG to PDF
 » Convert Powerpoint to PDF
 » Convert Publisher to PDF
 » Convert web pages to PDF
Full article list in the knowledgebase.