A
annoir
I am trying to print PDF documents using the code below and I get the
following error:
"Object reference not set to an instance of an object."
Am totally stumped. Can anybody help? I am using VS .NET 2003 on
Windows XP.
Thanks
Annie
Private Sub printPDFFile(ByVal strOutputFile As String)
Dim objStartInfo As New ProcessStartInfo
Dim objProcess As New System.Diagnostics.Process
If IsValidPrinter() Then
' set start info properties
With objStartInfo
.CreateNoWindow = True
.FileName = AcrobatReaderExecutable
.Arguments = "/t " & strOutputFile & " " &
ServicePrinterName
.UseShellExecute = True
.WindowStyle = ProcessWindowStyle.Hidden
.ErrorDialog = True
'.RedirectStandardError = True
End With
' start process
Try
objProcess = Process.Start(objStartInfo)
objProcess.Close()
'If Not objProcess.HasExited Then
' ' wait 40 seconds for graceful exit then kill it
' 'objProcess.WaitForExit(40000)
' ' kill process -- keeps it from hanging service
if it has not finished
' 'objProcess.Kill()
'End If
' print to event log
AddToEventLog("Attempting to print generated " &
getWordString() & " letter '" & strOutputFile & "' to printer [" &
ServicePrinterName & "]", EventLogEntryType.Information)
Catch ex As Exception
' error occurred
AddToEventLog("Error encountered while attempting to
print PDF file to printer [" & ServicePrinterName & "] " & vbCrLf &
ex.Message & vbCrLf & ex.Source & vbCrLf & ex.TargetSite.Name,
EventLogEntryType.Error)
End Try
Else
' printer not valid
AddToEventLog("The file '" & strOutputFile & "' cannot be
printed. The printer [" & ServicePrinterName & "] either is not valid
or has not been setup as a printer on this machine.",
EventLogEntryType.Error)
End If
End Sub
following error:
"Object reference not set to an instance of an object."
Am totally stumped. Can anybody help? I am using VS .NET 2003 on
Windows XP.
Thanks
Annie
Private Sub printPDFFile(ByVal strOutputFile As String)
Dim objStartInfo As New ProcessStartInfo
Dim objProcess As New System.Diagnostics.Process
If IsValidPrinter() Then
' set start info properties
With objStartInfo
.CreateNoWindow = True
.FileName = AcrobatReaderExecutable
.Arguments = "/t " & strOutputFile & " " &
ServicePrinterName
.UseShellExecute = True
.WindowStyle = ProcessWindowStyle.Hidden
.ErrorDialog = True
'.RedirectStandardError = True
End With
' start process
Try
objProcess = Process.Start(objStartInfo)
objProcess.Close()
'If Not objProcess.HasExited Then
' ' wait 40 seconds for graceful exit then kill it
' 'objProcess.WaitForExit(40000)
' ' kill process -- keeps it from hanging service
if it has not finished
' 'objProcess.Kill()
'End If
' print to event log
AddToEventLog("Attempting to print generated " &
getWordString() & " letter '" & strOutputFile & "' to printer [" &
ServicePrinterName & "]", EventLogEntryType.Information)
Catch ex As Exception
' error occurred
AddToEventLog("Error encountered while attempting to
print PDF file to printer [" & ServicePrinterName & "] " & vbCrLf &
ex.Message & vbCrLf & ex.Source & vbCrLf & ex.TargetSite.Name,
EventLogEntryType.Error)
End Try
Else
' printer not valid
AddToEventLog("The file '" & strOutputFile & "' cannot be
printed. The printer [" & ServicePrinterName & "] either is not valid
or has not been setup as a printer on this machine.",
EventLogEntryType.Error)
End If
End Sub