|
Word OLE VB |
Top Previous Next |
|
The Word OLE VB sample is a simple Windows console application that converts a MS Word document (C:\Test.doc) to PDF using Word OLE automation.
Source code ' the novapiLib packages must be added as a COM reference Const PRINTER_NAME As String = "<%SDK_SAMPLE_PRINTER%>" 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, "VB Word OLE", PROFILE_IS_Public If Err.Number <> 0 Then ' ignore profile exists error If NV_PROFILE_EXISTS <> Err.Number Then Debug.Print "Profile VB Word OLE already exists" Else Return End If End If On Error GoTo ErrorHandler: ' set the copy profile as active profile ... pNova.SetActiveProfile2 "VB Word OLE", PROFILE_IS_Public ' and set some options pNova.SetOptionString2 NOVAPDF_INFO_SUBJECT, "Word OLE document", "", PROFILE_IS_Public ' print word document Dim objWord As Object Dim objDoc As Object pNova.InitializeOLEUsage "Word.Application" Set objWord = CreateObject("Word.Application") pNova.LicenseOLEServer Set objDoc = objWord.Documents.Open("C:\Test.doc", False, True) objDoc.PrintOut False objDoc.Close False objWord.Quit False
' Return to previous settings pNova.SetActiveProfile2 activeProfile, bPublicProfile pNova.DeleteProfile2 "VB Word OLE", PROFILE_IS_Public Exit Sub ErrorHandler: Debug.Print Err.Number & ":" & Err.Description End Sub |