2

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).

  • LPR seems to ignore '-o sides=two-sided-long-edge' option, maybe is only available on UNIX.
  • I am using Spire.PDF but is comercial licensed and I can't select the printer. It prints to the default printer so I am configuring it every time.
sillo01
  • 604
  • 6
  • 13

2 Answers2

2

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.

ShawnW.
  • 1,771
  • 1
  • 12
  • 12
0

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.

MattK
  • 96
  • 2