C# .NET - Creating a print service - Asked By Henry Taylor on 16-Apr-18 05:04 PM

I need to be able to receive a byte array from a user and send that data on to a printer.

This sounds simple but it is not turning out that way.

byte[] bytes = File.ReadAllBytes(@"AppServer\Test_doc.txt");
string fileName = "Test_doc.txt";

PrintServer printServer = new PrintServer(@"\\PRINTERserver1");
PrintQueue printQueue = printServer.GetPrintQueue("PRINTERname");

PrintSystemJobInfo thisJob = printQueue.AddJob(fileName);

Stream myStream = thisJob.JobStream;
myStream.Write(bytes, 0, bytes.Length);

I see examples that claim this works but it does not.  I can see the document SPOOLING in the printer queue window but nothing ever comes out.

The printServer and printQueue objects are initializing correctly. When I look at their properties I see things that would not be there if a connection is not being made. Any help would appreciated.
Robbe Morris replied to Henry Taylor on 21-Apr-18 07:26 AM
this won't work for things like word docs and pdfs.  You'll have to launch those files in their software (via command line or specialized 3rd party libraries) and then print them.  Aspose has libraries for most file formats with built in printing from ASP.NET applications (server side).
Henry Taylor replied to Robbe Morris on 23-Apr-18 05:14 PM
Implemented ceTeDynamicPDF. So far it works fine. Haven't load tested yet but I am optimistic. Thanks Rob.