Silent Print a Document in a Windows Service

Hello,

This a tricky question, I'm using control PdfDocumentView to load an document and print directly to a printer ...

Code:
            PdfDocumentView pdfDocView = new PdfDocumentView();
            pdfDocView.Load(pathGeneratedPdf);
            pdfDocView.Print("name of printer");

This code is used in a Console Application , and runs fine.

If I try to run in an Windows Service, "access is denied" is showed. Is there a way to invoke Printing a Pdf in a
Windows Service ?

Best Regards,

João Guedes



3 Replies

GR Gangagowri Rajendran Syncfusion Team July 30, 2018 09:39 AM UTC

Hi João Guedes, 
 
Printing a file using System.Drawing.Printing is not supported in Windows Service. Since we are using System.Drawing.Printing namespace to print a PDF document using PdfDocumentView, it is not possible to achieve the same in Windows Service. 

The following MSDN link explains the problems occurred while printing a file using Windows Service.

https://msdn.microsoft.com/en-us/library/system.drawing.printing.aspx 

"Classes within the System.Drawing.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions."

As per the documentation, the System.Drawing.Printing namespace is not encouraged to be used within a Windows Service.

Please let us know if you need any other assistance. 
 
 
Regards, 
Gangagowri Rajendran 



JG João Guedes July 30, 2018 10:44 AM UTC

Hi Gangagowri Rajendran,

Thanks for the quick reply and the explanation.

Regards,
João Guedes


GR Gangagowri Rajendran Syncfusion Team August 1, 2018 04:34 AM UTC

Hi João Guedes, 

Thanks for your update, please let us know if you need any further assistance. We are always happy to help you. 

Regards, 
Gangagowri Rajendran 


Loader.
Up arrow icon