Search code examples
c#pdfprintingsvc

Printing with winspool.Drv-WritePrinter prints hundreds of pages with symbols instead of correct page


I have a svc that receives a string with a printer name and, after some things, it finishes printing a pdf document.

I'm using something like this code to print the pdf

https://vishalsbsinha.wordpress.com/2014/05/06/how-to-programmatically-c-net-print-a-pdf-file-directly-to-the-printer/

And it works perfectly on my computer/printer. But when I publish and deploy on the server, when I use the service it starts printing hundreds of pages filled with symbols instead of the expected one page pdf. The server does not have Adobe Acrobat installed (and neither I can install it) so I can't use other alternatives like 'new Process()->Verb="PrintTo".

The pdf fonts are Calibri and Arial, and they are installed on both my team and server.

Does anyone can tell me why does it prints on a wrong way and what alternatives do I have?

The model of the printer is: RICOH Aficio MP C4501 PCL 6


Solution

  • Your solution requires that the printer handles PDF files natively, and many printers don't support PDF. A printer driver translates from Windows GDI to the native format of the printer, but you're bypassing the printer driver by using WritePrinter. You will either need to use a different paper printer that supports PDF, or send the file to the printer using the printer driver instead of WritePrinter.