Public Class clsPDF_print_show Public Enum Enum_Art Drucken = 0 Anzeigen = 1 End Enum Public Function PrintPDF(ByVal sFilename As String, ByVal Art As Enum_Art) As Boolean PrintPDF = True Dim myProcess As New Process() Try 'Point the process to our Acrobat file myProcess.StartInfo.FileName = sFilename myProcess.StartInfo.WorkingDirectory = New IO.FileInfo(sFilename).DirectoryName 'Since we don't want to see Acrobat's UI (we just want the report printed) 'then suppress the UI and pass the "Print" verb to force Acrobat to only print myProcess.StartInfo.CreateNoWindow = True If Art = Enum_Art.Anzeigen Then myProcess.StartInfo.Verb = "Open" myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal Else myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden myProcess.StartInfo.Verb = "Print" End If myProcess.Start() 'Wait until Acrobat has finished heavy processing, or 10 seconds whichever comes first If Not myProcess.HasExited Then myProcess.WaitForInputIdle(10000) 'Attempt to close Acrobat so it's UI doesn't sit on the user's task bar 'loop until we suceed or until we timeout. If we timeout, kill Adobe Dim i As Integer = 1 Dim lbRunning As Boolean = True 'Da keine Kill Rechte auf den Vista Maschinen vorhanden sind, wird der Prozess nicht gekillt. lbRunning = False 'While lbRunning And i <= 20 ' 'sleep for 1/2 of a second ' System.Threading.Thread.Sleep(500) ' 'See if the Adobe will exit gracefully ' Select Case myProcess.HasExited ' Case True : lbRunning = False ' Case False : lbRunning = Not myProcess.CloseMainWindow ' End Select ' i += 1 'End While 'If it never closed gracefuly, force it out of memory If lbRunning AndAlso Not myProcess.HasExited Then myProcess.Kill() myProcess.Dispose() Catch ex As System.ComponentModel.Win32Exception PrintPDF = False Catch ex As Exception PrintPDF = False End Try End Function End Class