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 Jul 06, 2020 4:12 pm

Hi there

I am evaluating the Spire.Pdf library for printing thousands of files in a console service application running on a server. It needs to be able to print each PDF file asynchronously, but the latest free version of the Spire.Pdf library I have downloaded does not seem to support an async method for printing.

I know that I can create a new thread or start a background process for every print job but given the fact that the service application might be sending thousands of print jobs to our printer, this may not be a good solution as it will have performance issues and cause problems for other apps running on the same server.

Is there a way to make the Print function of the PdfDocument object async?

Thanks

mohammadarmin
 
Posts: 2
Joined: Mon Jul 06, 2020 3:23 pm

Tue Jul 07, 2020 7:12 am

Hello,

Thanks for your inquiry.
Sorry to tell you that our Spire.PDF does not provide a direct async method for printing. I'm afraid that you can only achieve your needs by starting a background process, etc.
If there is anything else we can do for you, just feel free to let us know.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue Jul 07, 2020 4:41 pm

Hi Rachel

Thanks for your reply and the confirmation.

I do have another issue. Sometimes I get the following error when printing files:

System.Drawing.Printing.InvalidPrinterException: Settings to access printer '\\printer' are not valid.
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(String printer)
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings pageSettings)
at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Spire.Pdf.PdfDocument.Print()

My code which creates a new PdfDocument intance is as follows:

var doc = new PdfDocument();
doc.LoadFromBytes(fileContent);
doc.PrintSettings.DocumentName = fileName;
doc.PrintSettings.PrinterName = printerName;
doc.PrintSettings.PrintController = new StandardPrintController();

The code runs in a console Windows service app on a Windows Server 2012.

The above issue happens irregularly. For instance, when I process and print a batch of say 100 files in a loop, it happends a few times.

I would appreciate it if you could suggests a solution or workaround.

mohammadarmin
 
Posts: 2
Joined: Mon Jul 06, 2020 3:23 pm

Wed Jul 08, 2020 3:32 am

Hello,

Thanks for your reply.
According to your information, the printer may not be accessible due to network problems. I suggest you can use the .NET printing API to print directly like the below code and see if the same issue happens.
Code: Select all
        public static void Print()
        {
            PrintDocument printDocument1 = new PrintDocument();
            var printerSettings = new System.Drawing.Printing.PrinterSettings();
            printerSettings.PrinterName = "\\\\PrintServerIP\\PrinterName";
            printDocument1.PrinterSettings = printerSettings;
            printDocument1.PrintPage += PrintDocument1_PrintPage;
            printDocument1.Print();
        }
        public static void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawString("Test print", new Font("Arial", 10), Brushes.Black, 100, 20);
            e.Graphics.PageUnit = GraphicsUnit.Inch;
        }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF