Word OLE VBNet - SDK sample

This article applies only to novaPDF. If you don't have it yet, you must download it first.

DOWNLOAD novaPDF
Feb 25, 2019

We strive to keep our articles as accurate as possible. If you notice any inconsistencies or outdated info please let us know.

Word OLE VBNet - SDK sample

Sample VBNet app that converts a MS Word document to PDF using OLE Automation.

Word OLE VBNet sample is a simple Microsoft Windows console application that converts a Microsoft Word document (an example path for the document would be C:\Test.docx) to a PDF using Word OLE automation and the novaPDF SDK application.

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.

Source Code

Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports novapiLib80

Module Module1
    '    <summary>
    '    The    main entry point for the application.
    '    </summary>
    Const PRINTER_NAME As String = "novaPDF SDK 8"
    Const PROFILE_NAME As String = "Word OLE VBNet"
    Const PROFILE_IS_PUBLIC As Integer = 0
    Const NOVAPDF_INFO_SUBJECT As Integer = 68

    Sub Main()

        ' create the NovaPdfOptions80 object
        Dim pNova As NovaPdfOptions80
        pNova = New NovaPdfOptions80
        Dim activeProfile As String = ""
        Dim newProfileID As String = String.Empty

        ' initialize the NovaPdfOptions80 object
        ' if you have an application license for novaPDF SDK, 
        pNova.Initialize(PRINTER_NAME, "")
        ' save old active profile id
        pNova.GetActiveProfile(activeProfile)
        ' create new profile
        pNova.AddProfile(PROFILE_NAME, PROFILE_IS_PUBLIC, newProfileID)
        'load the new profile
        pNova.LoadProfile(newProfileID)
        'and set some  options
        pNova.SetOptionString(NOVAPDF_INFO_SUBJECT, "C# Word OLE document")
        pNova.SaveProfile()
        'set the copy  profile as active profile ...
        pNova.SetActiveProfile(newProfileID)
        'set nova default printer
        pNova.SetDefaultPrinter()
        ' print word document
        Dim objWord As Object
        Dim objDoc As Object
        pNova.InitializeOLEUsage("Word.Application")
        objWord = CreateObject("Word.Application")
        pNova.LicenseOLEServer()
        objDoc = objWord.Documents.Open("C:\temp\test.docx", False, True)
        objDoc.PrintOut(False)
        objDoc.Close(False)
        objWord.Quit(False)

        ' restore active profile
        If activeProfile.Length > 0 AndAlso activeProfile.CompareTo(PROFILE_NAME) <> 0 Then
            pNova.SetActiveProfile(activeProfile)
            pNova.DeleteProfile(newProfileID)
        End If

        ' restore default printer
        pNova.RestoreDefaultPrinter()
    End Sub
End Module