Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon May 07, 2018 7:56 pm

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

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Tue May 08, 2018 6:00 am

Dear tlerner,

Thanks for your inquiry.
Firstly, we suggest using the latest Spire.Office Platinum (DLL Only) Version:3.4.2 if you were using old version. If the issue still happens, please share us following information here or send it to us(support@e-iceblue.com) via email for further investigation.
1. What code throw that exception
2. Input pdf document, better to provide a sample project for showing your issue.
3. The printer you were using, e.g. HP LaserJet P1007
4. OS and Region information, e.g. Win7 64bit, China/Chinese


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed May 09, 2018 7:02 pm

We currently have Spire.Office 3.4.0 installed and corresponding license. The application prints different forms to different printer drawers. When it needs to change the drawer ocassionaly (out of 70 forms, I received an error for 5) it throws an error.

I am attaching the code and and sample of the document. Also be aware that this is two page document, 1st page needs to be printed to letterhead (drawer2) and 2nd page should be printed to plain paper (drawer1). We use Canon printer, Windows2012 server with 64 bit.

Here is the error (I specific the line where error occurs sparatically!! in the attached PrintCode.sql).

PrintPage(PdfDocument PdfDoc, String IsLetterHead, Int32 startPage, Int32 endPage)
System.ComponentModel.Win32Exception (0x80004005): No process is on the other end of the pipe No process is on the other end of the pipe; IsLetterHead N; startPage 2; endPage 2

Please, let me know if you need an additional information. We plan to go live with this code by end of May.

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Wed May 09, 2018 7:13 pm

One more point. The error does not happen on development server, only on deployment.

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Wed May 09, 2018 8:56 pm

I found a work around, but this not what i'd like to have.

In the attached document, i have following sub with added code (reprint when error occurs)

Shared Sub PrintPage(ByVal PdfDoc As Spire.Pdf.PdfDocument, ByVal IsLetterHead As String, ByVal startPage As Integer, ByVal endPage As Integer)
Try
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.Print()

Catch ex As Exception
************************************** added following ****************
''try to print one more time
If iErrorCtr = 0 Then
Variables.sw.WriteLine(Now() & " --->Retry to print for DocId ..." )
PrintPage(PdfDoc, IsLetterHead, startPage, endPage)
iErrorCtr += 1
******************************************************
Else
Throw ex
End If
End Try

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Thu May 10, 2018 7:12 am

Dear tlerner,

Thanks for your information.
Could you please try to use the latest Spire.Office Platinum (DLL Only) Version:3.4.2 which includes more improvements than the version you were using ? Check if the version could solve your issue.
Besides, I didn't find your sample project/entire code and sample pdf here. Could you please upload it again or send it to us(support@e-iceblue.com) via email ? And since we don't have the corresponding device to reproduce your issue, please sharing following information to help us locate the issue.
1. The specific model of your Canon printer, e.g. Canon C3020.
2. Could you print successfully using only one tray, rather than two trays in your deployment environment ?
3. Use other API (e.g. the class PrintDocument under System.Drawing.Printing) to print and check if it could print without error. Sample code:
Code: Select all
            PrintDocument printDocument1 = new PrintDocument();
            var printerSettings = new System.Drawing.Printing.PrinterSettings();
            //printerSettings.PrinterName = "";
            printDocument1.PrinterSettings = printerSettings;         
            printDocument1.PrintPage += printDocument1_PrintPage;
            PrintDialog printDialog1 = new PrintDialog();
            printDialog1.Document = printDocument1;
            // in the dialog, you can set up the paper size, etc.
            printDialog1.UseEXDialog = true;
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                printDocument1.Print();
            }
        }
        private static int i = 0;
        private static void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Font font = new Font("Arial",12, FontStyle.Regular, GraphicsUnit.Point);
            e.Graphics.DrawString("12", font, Brushes.Black, 100, 10);
            e.Graphics.DrawString("12", font, Brushes.Black, 100, 600);
            if (i < 2)
            {               
                e.HasMorePages = true;
                i++;
            }
            else if(i==2)
            {
                e.HasMorePages = false;
            }
        }


4. Did you deploy on IIS ? Could you please provide the screenshot of IIS settings.

Many thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu May 10, 2018 3:12 pm

1. the printer model is Canon iR-ADV C7260/7270 PCL6
2. i can print to one tray successfully, but i need to print to different trays.
3. i tried using other API, but cannot figure out how to setup different trays.
4. I added a code and a sample files.

I need to print first page to the letterhead (drawer1) and second page to the plain paper (drawer 2).

Thank you for the help!

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Fri May 11, 2018 6:46 am

Dear tlerner,

Thanks for your answers.
Please try to use following code to print file with different trays, and then tell us the result. Thanks for your assistance.
Code: Select all
    Dim paperSources As System.Drawing.Printing.PrinterSettings.PaperSourceCollection
    Public Sub Print()
        Dim printDocument1 As PrintDocument = New PrintDocument
        Dim printerSettings = New System.Drawing.Printing.PrinterSettings
        printerSettings.PrinterName = "your printer"
        printDocument1.PrinterSettings = printerSettings
        paperSources = printDocument1.PrinterSettings.PaperSources
        AddHandler printDocument1.QueryPageSettings, AddressOf printDocument1_QueryPageSettings
        AddHandler printDocument1.PrintPage, AddressOf printDocument1_PrintPage

        Dim printDialog1 As PrintDialog = New PrintDialog
        printDialog1.Document = printDocument1
        printDialog1.UseEXDialog = True
        If (printDialog1.ShowDialog = DialogResult.OK) Then
            printDocument1.Print()
        End If
    End Sub
    Private i As Integer = 0

    Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim font As Font = New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point)
        e.Graphics.DrawString("test", font, Brushes.Black, 100, 10)
        e.Graphics.DrawString("test", font, Brushes.Black, 100, 600)
        If (i < 2) Then
            e.HasMorePages = True
            i = (i + 1)
        ElseIf (i = 2) Then
            e.HasMorePages = False
        End If
    End Sub
    Private Sub printDocument1_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs)
        If (i = 1) Then
            e.PageSettings.PaperSource = paperSources(0)
        Else
            e.PageSettings.PaperSource = paperSources(1)
        End If
    End Sub


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 11, 2018 5:37 pm

Thank you for your example. I still use Spire .dll for printing, but was able to setup different trays for different pages.
Can you please help me to determine the proper event handler to setup margins for different pages (1st page - letterhead with specific margins, 2nd page - plain paper with different margins). Here is the code that I have currently. Thanks a lot in advance!!

Shared Sub PrintPDF(ByVal FileName As String)
Dim PdfDoc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument
''load pdf file
PdfDoc.LoadFromFile(FileName)
''get number of pages
iTotalPages = PdfDoc.Pages.Count
''get printer name
PdfDoc.PrintSettings.PrinterName = Variables.PrinterAddress
PdfDoc.PrintSettings.DocumentName = Variables.FormID
PdfDoc.PrintSettings.SetPaperMargins(45, 10, 30, 15)

If Variables.LetterHead = "1" Then
iLetterheadPages = 2
Else
iLetterheadPages = 0
End If

''printing on letterhead and/or plain paper
AddHandler PdfDoc.PrintSettings.PaperSettings, AddressOf PdfDoc_PaperSourceSetup
PdfDoc.Print()
End Sub

Shared Sub PdfDoc_PaperSourceSetup(ByVal sender As Object, ByVal e As Spire.Pdf.Print.PdfPaperSettingsEventArgs)
'Get the letterhead paper source tray
If e.CurrentPaper <= iLetterheadPages Then
e.CurrentPaperSource = e.PaperSources(Variables.LetterHeadIndex)
''---->> CAN MARGIN BE SET AT THIS POINT OR SEE BELOW
Else
e.CurrentPaperSource = e.PaperSources(Variables.PlainPaperIndex)
''---->> CAN MARGIN BE SET AT THIS POINT
End If
End Sub

''---->> I NEED THIS TO BE AN EVENT HANDLER AS WELL OR SEE BELOW
Shared Sub PdfDoc_MarginSetup(ByVal PdfDoc As Spire.Pdf.PdfDocument, ByVal TotalPages As Integer)
If iLetterheadPages > 0 Then
PdfDoc.PrintSettings.SelectPageRange(1, 1)
PdfDoc.PrintSettings.SetPaperMargins(45, 10, 30, 15)
Else
PdfDoc.PrintSettings.SelectPageRange(2, 2)
PdfDoc.PrintSettings.SetPaperMargins(10, 10, 30, 10)
End If
End Sub

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Mon May 14, 2018 8:35 am

Dear tlerner,

Sorry for the late reply as weekend.
There is no way to set "Margin" for PDF in event handler while printing.
As per my understanding, you want to adjust the start position of the content in PDF. You have to create a new pdf which has different "Margin" and clone the content from original file then print it. You could refer to this guide. Also here is my sample code:
Code: Select all
        Dim testDoc As PdfDocument = New PdfDocument()
        testDoc.LoadFromFile("F:\sample.pdf")
        Dim newDoc As PdfDocument = New PdfDocument()
        For i As Integer = 0 To testDoc.Pages.Count - 1
            If i = 0 Then
                Dim OriPage As PdfPageBase = testDoc.Pages(i)
                Dim newPage As PdfPageBase = newDoc.Pages.Add(OriPage.Size, New PdfMargins(45, 10, 30, 15))
                newPage.Canvas.DrawTemplate(OriPage.CreateTemplate(), New PointF(0, 0))
            Else
                Dim OriPage As PdfPageBase = testDoc.Pages(i)
                Dim newPage As PdfPageBase = newDoc.Pages.Add(OriPage.Size, New PdfMargins(10, 10, 30, 10))
                newPage.Canvas.DrawTemplate(OriPage.CreateTemplate(), New PointF(0, 0))
            End If
        Next
        'your print code....
        newDoc.Print()

If I misunderstand your meaning, please describe your issue in detail and share your input document(if it is different from the file you sent before) and the expected result you want.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu May 17, 2018 7:40 am

Dear tlerner,

Greetings from your E-iceblue.
How is your issue going now ? Could you please give us some feedback at your convenience ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF