.NET Framework - Printing PDF from VB.NET class

Asked By annoir on 19-Jun-07 01:42 PM
I am trying to print PDF documents using the code below and I get the
following error:


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




Lucas replied on 19-Jun-07 01:55 PM
Is there an option to open Adobe Reader, then print?  I am unaware of
any internal PDF printing members.
annoir replied on 19-Jun-07 03:42 PM
I believe the Adobe Reader is initiated by this statement:

.FileName = AcrobatReaderExecutable

AcrobatReaderExecutable is derived from the config file which points
to the location of Adobe Reader.

(AcroRd32.exe).  Leave blank and service will find it automatically --
8.0\Reader" />

Annie
Lucas replied on 19-Jun-07 04:17 PM
I have a few applications that open PDFs in Reader.  I simply do
this

Process.Start("C:\Path\test.pdf") <-- Opens PDF in Reader

but I am not quite sure how to access keys in Reader to perform a
print programatically.