I have an application that prints PDF files using spire.pdf dll. Ocassionally I receive following error
System.ComponentModel.Win32Exception (0x80004005): No process is on the other end of the pipe.
Here is the code. Thank you in advance.
Dim PdfDoc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument
Dim iTotalPages As Integer = 0
Dim iPrintedPages As Integer = 0
Try
''load pdf file
PdfDoc.LoadFromFile(FileName)
''get number of pages
iTotalPages = PdfDoc.Pages.Count
''get printer name
PdfDoc.PrintSettings.PrinterName = Variables.PrinterAddress
'' set duplex printing if required
If Variables.Duplex = 1 And iTotalPages > 1 Then
PdfDoc.PrintSettings.Duplex = Drawing.Printing.Duplex.Vertical
iPrintedPages = 2
Else
PdfDoc.PrintSettings.Duplex = Drawing.Printing.Duplex.Simplex
iPrintedPages = 1
End If
''start printing on letterhead, consecutive pages will be printed on plain paper
If Variables.LetterHead = "1" Then
PrintPage(PdfDoc, "Y", 1, iPrintedPages)
If iTotalPages > iPrintedPages Then PrintPage(PdfDoc, "N", iPrintedPages + 1, iTotalPages)
Else
''printing on plain paper
PrintPage(PdfDoc, "N", 1, iTotalPages)
End If
End If
''if no imaging required, delete the pdf file
If Variables.Image = 0 Then
Dim f1 As New FileInfo(FileName)
If f1.Exists Then f1.Delete()
End If
Catch ex As Exception
...
Throw ex
End Try
Shared Sub PrintPage(ByVal PdfDoc As Spire.Pdf.PdfDocument, ByVal IsLetterHead As String, ByVal startPage As Integer, ByVal endPage As Integer)
If IsLetterHead = "Y" Then
AddHandler PdfDoc.PrintSettings.PaperSettings, AddressOf PaperSourceLetterHead
Else
AddHandler PdfDoc.PrintSettings.PaperSettings, AddressOf PaperSourcePlainPaper
End If
PdfDoc.PrintSettings.SelectPageRange(startPage, endPage)
PdfDoc.PrintSettings.PrintController = New Drawing.Printing.StandardPrintController
PdfDoc.Print()
End Sub
Shared Sub PaperSourceLetterHead(ByVal sender As Object, ByVal e As Spire.Pdf.Print.PdfPaperSettingsEventArgs)
'Get the paper source trays collection
Dim sources() As System.Drawing.Printing.PaperSource = e.PaperSources
For i As Integer = 0 To sources.Length - 1
If sources(i).SourceName = Variables.LetterHeadSource Then
e.CurrentPaperSource = sources(i)
Exit For
End If
Next i
End Sub