Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27036

Process.start to print PDF is inconsistent.

$
0
0
Hi,

I have a sub to print PDF to a specific printer and it works great exept for one case... If the PDF to print (Impression) is from a Merge fonction that I have in my program, it prints flawlwssly. If I don't use the Merge fonction (Impression(D2)), the Process.WaitForInputIdle() acts like a runtime...

I tried to pause the program but it seems to work inconsistently.

I'm out of idea. Can you guys help

thanks...


Code:

Public Sub PrintFinalPDF()

        Dim strDefaultPrinterName As String
        Dim strPrinterName As String

        If DefaultPrinter.DefaultPrinterName <> "" Then
            'Save Default Printer Name
            strDefaultPrinterName = DefaultPrinter.DefaultPrinterName
            Debug.Print(strDefaultPrinterName)
            'TODO Change Default Printer
            If radProduction.Checked = True Then
                DefaultPrinter.DefaultPrinterName = "iR5050 Staple"
            End If
            If radPrototype.Checked = True Then
                If bolD2Séparé = True AndAlso _
                bolD2 = True Then
                    DefaultPrinter.DefaultPrinterName = "iR5050 Staple"
                Else
                    DefaultPrinter.DefaultPrinterName = "iR5050 Staple PROTO"
                End If
            End If
            '----------------------------------------------------------------------------------------------------
            Dim sReport = strMergedFileToPrint              'Complete name/path of PDF file
            Dim starter As New ProcessStartInfo
            Dim Process As New Process()

            strPrinterName = DefaultPrinter.DefaultPrinterName
            Debug.Print(strPrinterName)

#If DEBUG Then
            'Restore Default Printer
            DefaultPrinter.DefaultPrinterName = strDefaultPrinterName
            GoTo PROC_NO_IMPRESSION
#End If

            Process.StartInfo = starter
            Process.StartInfo.UseShellExecute = True
            Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            Process.StartInfo.FileName = strMergedFileToPrint
            Process.StartInfo.Verb = "print"
            Process.Start()
            'TODO trouver pourquoi le (D2) fait un runtime
            If strMergedFileToPrint.Contains("Impression(D2).PDF") = False Then
                Process.WaitForInputIdle()
            Else
                System.Threading.Thread.Sleep(7000)
            End If
            Process.CloseMainWindow()

            '----------------------------------------------------------------------------------------------------
            'Restore Default Printer
            DefaultPrinter.DefaultPrinterName = strDefaultPrinterName
        End If

PROC_NO_IMPRESSION:

    End Sub


Viewing all articles
Browse latest Browse all 27036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>