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.

Fri Sep 17, 2021 2:29 am

Hi;
We have the following exception when printing multiple PDFs (up to 120 in same time) of one, 2 or 3 pages .
Has anyone ever encountered this problem ?
Thank you for your help


Here's my piece of C# code Framework 4.6

Var fullname = “MyPdfFullPath”
Spire.Pdf.PdfDocument docToPrint = new Spire.Pdf.PdfDocument();
docToPrint.LoadFromFile(fullname);
docToPrint.PrintSettings.DocumentName = fullname;
docToPrint.PrintSettings.PrinterName = “MyPrinterName”;
docToPrint.PrintSettings.SelectPageRange(1, docToPrint.Pages.Count);
docToPrint.PrintSettings.EndPrint += new PrintEventHandler(Document_endPrint); // Occurs when the last page of the document has send to the printer
docToPrint.Print();

Exception
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF point, StringFormat format)
at spr⎯.ᜀ(Graphics A_0, spr⎬ A_1, Boolean A_2, Boolean A_3)
at spr⎯.ᜁ(Graphics A_0, spr⎬ A_1, Boolean A_2, Boolean A_3)
at spr⎬.ᜀ(String A_0, spr␏ A_1, String A_2, Boolean A_3)
at spr⎬.ᜀ(String[] A_0, String A_1)
at spr⎬.ᜀ(spr␒ A_0)
at spr⎬.ᝄ()
at spr⎬.ᜍ(Boolean A_0)
at spr㖫.ᜌ(Graphics A_0, spr⎣ A_1, spr␑ A_2, spr␓ A_3, Image A_4)
at spr∡.ᜀ(PrintPageEventArgs A_0, PdfPageBase A_1, RectangleF A_2)
at spr∡.ᜃ(PrintPageEventArgs A_0)
at spr∡.ᜀ(Object A_0, PrintPageEventArgs A_1)
at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Spire.Pdf.PdfDocument.Print()

alilimakhlouf
 
Posts: 3
Joined: Mon Nov 26, 2018 7:11 pm

Fri Sep 17, 2021 5:41 am

Hi Alili,

Thanks for your inquiry.
I did some initial tests based on your code, but I did not reproduce the error you mentioned. Compared to the free version, the commercial version is more stable and contains more bug fixes. Therefore, I suggest you download the latest commercial version of Spire.PDF 7.9.2 and test again. If this error persists, in order to help us investigate further, please provide your input PDF files. Thanks in advance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Sep 17, 2021 1:08 pm

Hi Andy;

this is our system configuration :
OS windows server 2012
we print via program running under the same server (windows server 2012)

The problem appears when printing several PDFs (about 120 to 150 ) of one or 2 pages in one shot.

thank you

alilimakhlouf
 
Posts: 3
Joined: Mon Nov 26, 2018 7:11 pm

Sat Sep 18, 2021 10:05 am

Thanks for your sharing.

Do you print the files using multiple threads? I simulated some documents and printed them in one shot using multiple threads in an environment similar to yours. But no error was encountered. This issue may be related to your documents. Could you please provide your full test code and share some of your test documents with us to help us reproduce the issue? You can upload the files here or sent them to us via email([email protected]). Thanks in advance for your assistance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Sep 21, 2021 12:47 am

Thank you very much for your reply;
Here are some PDF formats that generate errors when printed via the Spire.PDF Dll
If you test printing the same PDF in a 120-iteration loop, you'll probably reproduce the exception.
Sincerely Alili

alilimakhlouf
 
Posts: 3
Joined: Mon Nov 26, 2018 7:11 pm

Tue Sep 21, 2021 10:15 am

Hi,

Thanks for your feedback.
I simulated your scenario to test same PDF in more than 120-iteration loop, but didn't reproduce your issue on my side. I suggest that you try to dispose the Pdf document after printing, below is my testing code for your reference. If it doesn't help, please feel free to write back.
Code: Select all
Spire.Pdf.PdfDocument docToPrint = new Spire.Pdf.PdfDocument();
for (int i = 0; i < 200; i++)
{
    docToPrint.LoadFromFile(@"M59K27212601533037000001_test_20210920_4_21263770_21259127_141_20210920-134333-713.pdf");
    docToPrint.PrintSettings.DocumentName = "name";
    docToPrint.PrintSettings.PrinterName = "Microsoft XPS Document Writer";
    docToPrint.PrintSettings.SelectPageRange(1, docToPrint.Pages.Count);
    docToPrint.PrintSettings.PrintToFile("D:\\printout\\print" + i+".xps");
    docToPrint.Print();
    //dispose docToPrint
    docToPrint.Dispose();
}

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF

cron