Print PDF file in C# - PrintDocumentWithSettings taking a long time to print

@manikantakondepati

The method PrintDocumentWithSettings usually prints the PDF document by applying the specified Page settings. Can you please explain in what perspective you want the details behind this method?

@asad.ali
What is the method “PrintDocumentWithSettings” doing for printing a document to a network printer going thru print server and NOT for a locally configured printer(configured as TCP/IP printer and not going thru print server)?. Is there a difference between these two ways of printing when using Aspose library.

We tried to compare network packets that were captured for the below scenarios:

On an App server, I tried to print a PDF thru print server using adobe reader: 135 packets sent and received when printing from Adobe reader to the print server. Took about 2 seconds to print.

On an App server, I tried to print a PDF thru print server using .Net Aspose API call: 77,000 packets sent and received when printing from application using Aspose to the print server. Took about 45 seconds to print.

On an App server, I tried to print a PDF to local printer (configured as TCP/IP printer and not going thru print server) using .Net Aspose API call- 162 packets sent and received when printing from application using Aspose API to a network printer that was created as local print queue on the app server there by bypassing the Print server. Took about 2 seconds to print.

Considering the above difference, we are wondering why there is so much difference in the number of packets sent to network printer when using Aspose library.

Also, please note that when using Aspose library and trying to print to local printer, for a 2 page PDF document, it is taking approx 2 seconds and for a 37 page PDF document, it takes approx 16 seconds. So that tells me if the number of pages in PDF increase that increases the time taken by aspose library as well. What is an acceptable time it takes for the Aspose library to process a 37 page PDF document?

Please let me know if you have any questions.

@manikantakondepati

PdfViewer.PrintDocumentWithSettings() method is a part of PrintDocument:

  • generate Default PageSettings;
  • generate Default PrinterSettings;
  • call method PrintDocumentWithSettings.

In PrintDocumentWithSettings, you can set some settings (Margins, Copies, PrinterName, etc).

The method works based on PrintDocument from System.Drawing.Printing.

PrintDocument:
Defines a reusable object that sends output to a printer. 

Furthermore, thanks for providing details of the investigation made by you. We have recorded this information along with the earlier logged ticket and will investigate it from this perspective as well. We will surely inform you once we have some updates in this regard.

We apologize for the inconvenience caused.

@asad.ali
Thanks for the information, we are trying to use a UNC path for the printer name attribute and it appears that each time to try to print, the “PrintDocumentWithSettings” method tries to install the driver even thought the printer driver is installed. This driver loading is taking about 40 seconds. How can we adjust the code so that the installed driver is used?

@manikantakondepati

We really regret that we cannot share further feedback without investigating the logged ticket in more detail. We have recorded all the information that you provided and will analyze this case from this perspective. We will let you know once we make some significant progress towards ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali Hello Ali, wishing you a happy new year, it’s been 20 days since your last update and I understand that Aspose works on first come first basis, can we at least get a sense of timeline, as to when this issue could possibly be resolved. We will be forced to look at alternate vendor if this issue is not resolved at the earliest, since the project we are working on is of high priority among upper management. Thank You… looking forward to resolution…

@manikantakondepati

We are afraid that the earlier logged ticket has not been scheduled for investigation yet. Hence, some reliable ETA cannot be shared from our side. However, we have recorded your concerns and logged them under the ticket as well. We will surely consider them during ticket analysis and let you know as soon as we have some investigation results and feedback to share with you regarding ticket resolution or fixing ETA. We greatly appreciate your patience and comprehension in this regard.

We apologize for your inconvenience.

@manikantakondepati

After the investigation we’re afraid there’s not much that we can do about this problem at the moment. The PdfViewer currently uses the default .NET System.Drawing.Printing API, based on the GDI+ API, and unfortunately it indeed can be very slow when used with network printers. You may check this out by making a minimal sample app that references only the System.Drawing.Common library, and not the Aspose.PDF, and trying to print anything manually with a PrintDocument class. We suppose, the delays are going to be similar to the observed with the Aspose.PDF.

That said, since we’ve updated the PdfViewer API to use our own types instead of System.Drawing ones, there should be less requests to a printer to obtain its capacities when working with PrinterSettings and PageSettings properties. So please try if the printing time has improved in the latest version of the library.

Moreover, we’re working on a printing subsystem overhaul that would in future give us an ability to provide alternate print handlers to replace the System.Drawing.Printing based one, and some of these handlers may exhibit better performance with network printers. Unfortunately, We are unable to give you an ETA for this feature at the moment (it’s H2 2024 now, but may move even further right due to a sheer number of needed changes), and emergence of alternate print handlers is an even more remote prospective.

Re: downloading printer drivers each time the printer is called. It seems to be either a System.Drawing.Printing problem or a printer setup problem. Please check if the remote printer connection is set up on the local machine, and if the correct driver is installed on the client.

Re: bad performance with the virtual printer. This seems to be a separate problem, not related to requests to a network printer, so please provide a document that allows to reproduce the problem with the virtual printer, and we will create a task to investigate and improve the performance.