|
Word OLE VBNet |
Top Previous Next |
|
The Word OLE VBNet sample is a simple Windows console application that converts a MS Word document (C:\Test.doc) to PDF using Word OLE automation.
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 = "<%SDK_SAMPLE_PRINTER%>" Const PROFILE_NAME As String = "Word OLE 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) ' 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:\Test.doc", False, True) objDoc.PrintOut(False) objDoc.Close(False) objWord.Quit(False) ' restore active profile pNova.SetActiveProfile(activeProfile, nActivePublic) pNova.DeleteProfile(PROFILE_NAME, PROFILE_IS_Public) ' restore default printer pNova.RestoreDefaultPrinter() Catch e As System.Runtime.InteropServices.COMException MessageBox.Show(e.Message) Catch e As Exception MessageBox.Show(e.Message) End Try End Sub
End Module |