Reputation: 614
I have an ASP Web API runing on IIS (Windows server 2008 r2). The sever has two printers available over network (same model, kyocera fs-4200).
I need to select the printer by code and print a PDF document double sided (dúplex).
Upvotes: 3
Views: 10644
Reputation: 1852
You can do:
File.Copy(yourPDFFile, @"\\yourservernname\yourprintername", true);
OR create a stream and stuff it through a Socket
Socket s = new Socket(SocketType.Stream, ProtocolType.Tcp)
IPAddress prnterIP = IPAddress.Parse(your ipaddress);
IPEndPoint endPoint = new IPEndPoint(prnterIP, 0); //<-- 0 here means any port, can be explicitly set
s.Connect(endPoint);
s.Send(File.ReadAllBytes(path to your PDF file));
s.Close();
The latter is more verbose, but seems to work better.
Reference here: Send text file directly to network printer
Possible issues with permissions there though with you running in ASP.NET, you may have to adjust accordingly.
Upvotes: 2
Reputation: 106
Is it possible for you to set up in Windows Server the printer you want to print so that it prints duplex by default? If so, it looks like the Kyocera FS-4200DN will accept PDF files directly for printing, so you might be able to copy it directly via a command-line process:
copy /b filename.pdf port:
Where port: is the port Windows assigned to the printer when installed on the system.
Alternately, it looks like the printer may use a job definition language called PRESCRIBE, where this supports duplex commands. It might be possible to prepend PRESCRIBE commands to enable duplexing to the PDF data and then send the PRESCRIBE+PDF data stream directly. https://www.kyoceradocumentsolutions.fr/index/document_solutions/outputmanagement/prescribe.-contextmargin-99204-contextmargingeneralcontextteaserGC-87757-File.cpsdownload.tmp/Manuel%20des%20commandes%20Prescribe.PDF suggests that the DUPX command can be used. I don't have a Kyocera printer to try this out with, so I can't say for sure it will work.
Upvotes: 0