Popup of nova driver when appending data
Posted: Mon Nov 29, 2010 2:50 pm
Hi All,
I have created a vb-script to create a PDF document and then add a *.doc, *.docx, *.xls or *.xlsx file to this PDF file.
When I run the program this 'sometimes' succeeds, but also sometimes failes. When it failed, it does not append it to the original file name, but the nova PDF driver comes with a popup screen. In this screen a file name is suggested (rad*.PDF). When I press the SAVE button ,this RAD file consists of the converted DOC document, but is was not appended to the original file name.
Can anyone help me with this? I use version 7.0 build 329 of the novapdf driver (novaPDF for SDK v7)
Part of the program:
Public Function CSAddAttachment(ByVal PrintJob As e4layout.ILayoutTransaction, ByVal sAttachment As String) As efprocess.ProcessInvoiceResult
On Error GoTo ErrorHandler:
Dim sPrinterName As String
Dim sFileName As String
Dim sExtension As String
Dim sActiveProfile As String
Dim lActiveProfilePublic As Long
Dim lPosLeft As Long
Dim lDocTeller As Long
Dim lContinue As Long
sPrinterName = ""
sFileName = ""
sExtension = ""
'Select the correct PDF printer
If PdfPrinterPresent(sPrinterName) Then
Set pNova = Nothing
Set pNova = New NovaPdfOptions
With pNova
'initilize the PDF printer
.InitializeSilent sPrinterName, NOVA_USER, NOVA_KEY, ""
'.InitializeSilent sPrinterName, "", "", ""
'and set it to default for this process
.SetDefaultPrinter
'Get the current profile
.GetActiveProfile sActiveProfile, lActiveProfilePublic
' and make a copy of it (to restore it later)
On Error Resume Next
.CopyProfile sActiveProfile, PROFILE_NAME, PROFILE_IS_PUBLIC
If Err.Number <> 0 Then
' ignore profile exists error
If NV_PROFILE_EXISTS = Err.Number Then
Debug.Print "Profile Randstad facturering already exists"
Else
Return
End If
End If
'On Error GoTo ErrorHandler:
'set the copy profile as active profile ...
'and adjust a number of settings
'.SetOptionLong NOVAPDF_SAVE_DESTINATION, False, PROFILE_NAME, PROFILE_IS_PUBLIC
'don't prompt when saving
.SetOptionLong NOVAPDF_SAVE_PROMPT, False, PROFILE_NAME, PROFILE_IS_PUBLIC
lPosLeft = InStrRev(m_sCSPDF, "\")
'but store it directly in the main PDF file
.SetOptionString NOVAPDF_SAVE_FOLDER, Left(m_sCSPDF, (lPosLeft - 1)), PROFILE_NAME, PROFILE_IS_PUBLIC
.SetOptionString NOVAPDF_SAVE_FILE, Right(m_sCSPDF, Len(m_sCSPDF) - lPosLeft), PROFILE_NAME, PROFILE_IS_PUBLIC
'and append data when it already exists
.SetOptionLong NOVAPDF_SAVE_CONFLICT_STRATEGY, FILE_CONFLICT_STRATEGY_APPEND, PROFILE_NAME, PROFILE_IS_PUBLIC
.SetOptionLong NOVAPDF_SILENT_PRINT, True, PROFILE_NAME, PROFILE_IS_PUBLIC
.SetOptionLong NOVAPDF_ACTION_OPEN_DOCUMENT, False, PROFILE_NAME, PROFILE_IS_PUBLIC
'.SetOptionLong NOVAPDF_ACTION_USE_DEFAULT_VIEWER, False, PROFILE_NAME, PROFILE_IS_PUBLIC
'make the profile active
.SetActiveProfile PROFILE_NAME, PROFILE_IS_PUBLIC
End With
'Get the document data and type
ReadAttachedDocument (sAttachment)
sExtension = GetAttachmentType(sAttachment)
sFileName = OpenAttachment(sExtension)
If Len(Trim(sFileName)) > 4 Then
Select Case UCase(sExtension)
Case "DOC", "DOCX"
' print word document
Dim objWord As Object
Dim objDoc As Object
pNova.InitializeOLEUsage "Word.Application"
Set objWord = CreateObject("Word.Application")
pNova.LicenseOLEServer
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'Register Event window and File saved event
Call pNova.RegisterEventWindow(hWnd)
Call pNova.RegisterNovaEvent(NOVAPDF_EVENT_FILE_SAVED)
Set objDoc = objWord.Documents.Open(Trim(sFileName), False, True)
objDoc.PrintOut False
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'wait till the event PDF file saved is fired by pNova
'On succes Unregister Window/event else wait.....
lContinue = 1
Do While lContinue <> 0
Call pNova.WaitForNovaEvent(60000, lContinue)
Loop
Call pNova.UnRegisterEventWindow
objDoc.Close False
objWord.Quit False
Set objWord = Nothing
Set objDoc = Nothing
Case "XLS", "XLSX"
' print excel sheet
Dim objExcel As Object
pNova.InitializeOLEUsage "Excel.Application"
Set objExcel = CreateObject("Excel.Application")
pNova.LicenseOLEServer
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'Register Event window and File saved event
Call pNova.RegisterEventWindow(hWnd)
Call pNova.RegisterNovaEvent(NOVAPDF_EVENT_FILE_SAVED)
objExcel.Workbooks.Open sFileName
objExcel.Workbooks(1).PrintOut
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'wait till the event PDF file saved is fired by pNova
'On succes Unregister Window/event else wait.....
lContinue = 1
Do While lContinue <> 0
Call pNova.WaitForNovaEvent(60000, lContinue)
Loop
Call pNova.UnRegisterEventWindow
objExcel.Workbooks(1).Close
objExcel.Workbooks(1).Quit
Set objExcel = Nothing
Case "PDF"
' wm_Nova_FileSaved = RegisterWindowMessage(MSG_NOVAPDF2_FILESAVED)
' wm_Nova_PrintError = RegisterWindowMessage(MSG_NOVAPDF2_PRINTERROR)
'
' If oldHandler <> 0 Then
' oldHandler = SetWindowLongApi(hwnd, GWL_WNDPROC, oldHandler)
' End If
' oldHandler = SetWindowLongApi(hwnd, GWL_WNDPROC, AddressOf VB_WindowProc)
' Dim r As Long
'Start the PDF print action (Use Acrobat Reader!) in a shell process via ShellExecute
pNova.RegisterEventWindow hWnd
Call pNova.RegisterNovaEvent(NOVAPDF_EVENT_FILE_SAVED)
pNova.LicenseShellExecuteFile sFileName
ShellPrintFile sFileName, GetActiveWindow()
' r = ShellExecute(hwnd, "print", sFileName, "", "", SW_HIDE)
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'wait till the event PDF file saved is fired by pNova
'On succes Unregister Window/event else wait.....
lContinue = 1
Do While lContinue <> 0
Call pNova.WaitForNovaEvent(60000, lContinue)
Loop
pNova.UnRegisterEventWindow
' oldHandler = SetWindowLongApi(hwnd, GWL_WNDPROC, oldHandler)
'Kill the Acrobat Reader Process so the process can go no
TerminateEXE ("AcroRd32.exe")
Case Else
'no action
End Select
' Return to previous settings
End If
DeleteTempAttachment (sFileName)
'Restore the original profile
pNova.SetActiveProfile sActiveProfile, lActiveProfilePublic
pNova.DeleteProfile PROFILE_NAME, PROFILE_IS_PUBLIC
'restore default printer
pNova.RestoreDefaultPrinter
Set pNova = Nothing
End If
Exit Function
ErrorHandler:
'Restore the original profile
I have created a vb-script to create a PDF document and then add a *.doc, *.docx, *.xls or *.xlsx file to this PDF file.
When I run the program this 'sometimes' succeeds, but also sometimes failes. When it failed, it does not append it to the original file name, but the nova PDF driver comes with a popup screen. In this screen a file name is suggested (rad*.PDF). When I press the SAVE button ,this RAD file consists of the converted DOC document, but is was not appended to the original file name.
Can anyone help me with this? I use version 7.0 build 329 of the novapdf driver (novaPDF for SDK v7)
Part of the program:
Public Function CSAddAttachment(ByVal PrintJob As e4layout.ILayoutTransaction, ByVal sAttachment As String) As efprocess.ProcessInvoiceResult
On Error GoTo ErrorHandler:
Dim sPrinterName As String
Dim sFileName As String
Dim sExtension As String
Dim sActiveProfile As String
Dim lActiveProfilePublic As Long
Dim lPosLeft As Long
Dim lDocTeller As Long
Dim lContinue As Long
sPrinterName = ""
sFileName = ""
sExtension = ""
'Select the correct PDF printer
If PdfPrinterPresent(sPrinterName) Then
Set pNova = Nothing
Set pNova = New NovaPdfOptions
With pNova
'initilize the PDF printer
.InitializeSilent sPrinterName, NOVA_USER, NOVA_KEY, ""
'.InitializeSilent sPrinterName, "", "", ""
'and set it to default for this process
.SetDefaultPrinter
'Get the current profile
.GetActiveProfile sActiveProfile, lActiveProfilePublic
' and make a copy of it (to restore it later)
On Error Resume Next
.CopyProfile sActiveProfile, PROFILE_NAME, PROFILE_IS_PUBLIC
If Err.Number <> 0 Then
' ignore profile exists error
If NV_PROFILE_EXISTS = Err.Number Then
Debug.Print "Profile Randstad facturering already exists"
Else
Return
End If
End If
'On Error GoTo ErrorHandler:
'set the copy profile as active profile ...
'and adjust a number of settings
'.SetOptionLong NOVAPDF_SAVE_DESTINATION, False, PROFILE_NAME, PROFILE_IS_PUBLIC
'don't prompt when saving
.SetOptionLong NOVAPDF_SAVE_PROMPT, False, PROFILE_NAME, PROFILE_IS_PUBLIC
lPosLeft = InStrRev(m_sCSPDF, "\")
'but store it directly in the main PDF file
.SetOptionString NOVAPDF_SAVE_FOLDER, Left(m_sCSPDF, (lPosLeft - 1)), PROFILE_NAME, PROFILE_IS_PUBLIC
.SetOptionString NOVAPDF_SAVE_FILE, Right(m_sCSPDF, Len(m_sCSPDF) - lPosLeft), PROFILE_NAME, PROFILE_IS_PUBLIC
'and append data when it already exists
.SetOptionLong NOVAPDF_SAVE_CONFLICT_STRATEGY, FILE_CONFLICT_STRATEGY_APPEND, PROFILE_NAME, PROFILE_IS_PUBLIC
.SetOptionLong NOVAPDF_SILENT_PRINT, True, PROFILE_NAME, PROFILE_IS_PUBLIC
.SetOptionLong NOVAPDF_ACTION_OPEN_DOCUMENT, False, PROFILE_NAME, PROFILE_IS_PUBLIC
'.SetOptionLong NOVAPDF_ACTION_USE_DEFAULT_VIEWER, False, PROFILE_NAME, PROFILE_IS_PUBLIC
'make the profile active
.SetActiveProfile PROFILE_NAME, PROFILE_IS_PUBLIC
End With
'Get the document data and type
ReadAttachedDocument (sAttachment)
sExtension = GetAttachmentType(sAttachment)
sFileName = OpenAttachment(sExtension)
If Len(Trim(sFileName)) > 4 Then
Select Case UCase(sExtension)
Case "DOC", "DOCX"
' print word document
Dim objWord As Object
Dim objDoc As Object
pNova.InitializeOLEUsage "Word.Application"
Set objWord = CreateObject("Word.Application")
pNova.LicenseOLEServer
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'Register Event window and File saved event
Call pNova.RegisterEventWindow(hWnd)
Call pNova.RegisterNovaEvent(NOVAPDF_EVENT_FILE_SAVED)
Set objDoc = objWord.Documents.Open(Trim(sFileName), False, True)
objDoc.PrintOut False
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'wait till the event PDF file saved is fired by pNova
'On succes Unregister Window/event else wait.....
lContinue = 1
Do While lContinue <> 0
Call pNova.WaitForNovaEvent(60000, lContinue)
Loop
Call pNova.UnRegisterEventWindow
objDoc.Close False
objWord.Quit False
Set objWord = Nothing
Set objDoc = Nothing
Case "XLS", "XLSX"
' print excel sheet
Dim objExcel As Object
pNova.InitializeOLEUsage "Excel.Application"
Set objExcel = CreateObject("Excel.Application")
pNova.LicenseOLEServer
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'Register Event window and File saved event
Call pNova.RegisterEventWindow(hWnd)
Call pNova.RegisterNovaEvent(NOVAPDF_EVENT_FILE_SAVED)
objExcel.Workbooks.Open sFileName
objExcel.Workbooks(1).PrintOut
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'wait till the event PDF file saved is fired by pNova
'On succes Unregister Window/event else wait.....
lContinue = 1
Do While lContinue <> 0
Call pNova.WaitForNovaEvent(60000, lContinue)
Loop
Call pNova.UnRegisterEventWindow
objExcel.Workbooks(1).Close
objExcel.Workbooks(1).Quit
Set objExcel = Nothing
Case "PDF"
' wm_Nova_FileSaved = RegisterWindowMessage(MSG_NOVAPDF2_FILESAVED)
' wm_Nova_PrintError = RegisterWindowMessage(MSG_NOVAPDF2_PRINTERROR)
'
' If oldHandler <> 0 Then
' oldHandler = SetWindowLongApi(hwnd, GWL_WNDPROC, oldHandler)
' End If
' oldHandler = SetWindowLongApi(hwnd, GWL_WNDPROC, AddressOf VB_WindowProc)
' Dim r As Long
'Start the PDF print action (Use Acrobat Reader!) in a shell process via ShellExecute
pNova.RegisterEventWindow hWnd
Call pNova.RegisterNovaEvent(NOVAPDF_EVENT_FILE_SAVED)
pNova.LicenseShellExecuteFile sFileName
ShellPrintFile sFileName, GetActiveWindow()
' r = ShellExecute(hwnd, "print", sFileName, "", "", SW_HIDE)
'[MARI1860 01-10-2010]BR 34.161.640 Wait for PDF print to be finished
'wait till the event PDF file saved is fired by pNova
'On succes Unregister Window/event else wait.....
lContinue = 1
Do While lContinue <> 0
Call pNova.WaitForNovaEvent(60000, lContinue)
Loop
pNova.UnRegisterEventWindow
' oldHandler = SetWindowLongApi(hwnd, GWL_WNDPROC, oldHandler)
'Kill the Acrobat Reader Process so the process can go no
TerminateEXE ("AcroRd32.exe")
Case Else
'no action
End Select
' Return to previous settings
End If
DeleteTempAttachment (sFileName)
'Restore the original profile
pNova.SetActiveProfile sActiveProfile, lActiveProfilePublic
pNova.DeleteProfile PROFILE_NAME, PROFILE_IS_PUBLIC
'restore default printer
pNova.RestoreDefaultPrinter
Set pNova = Nothing
End If
Exit Function
ErrorHandler:
'Restore the original profile