Click here to Skip to main content
15,748,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im using below code for print PDF files in website
string PathToExecutable = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
var PrintFileToPrinter = string.Format("/t \"{0}\" \"{1}\"", FilePath, PrinterName);
var args = string.Format("{0}", PrintFileToPrinter);
Process process = new Process();
process.StartInfo.FileName = PathToExecutable;
process.StartInfo.Arguments = args;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

I just want to print files in local network printers, and without preview. In my local computer(development environment) it worked fine, but after publishing to local Server(windows 2008), this function is not working.

can anyone help or give some suggestion?

1 solution

It works locally because the client and server are the same machine and the server code has access to the client resources. Once deployed the server and client are no longer the same machine. You can't access client resources from server code, you can't print to the local printer using server code. You can use window.print on the client and that will trigger a print confirmation dialog which you can't avoid.

Think about it....printing costs money, would you want websites printing to your printer without your intervention?
Share this answer
chenghuichao 14-May-15 10:39am    
Yes, I know this,the resources are located in server side, and I just want to print the files in server
F-ES Sitecore 14-May-15 10:46am    
You can't. Not unless you set up some kind of virtual device on the server that will print to the device on the client, or set the client's printer up as a network printer on the server. But you sure can't print direct to the client's printer.
chenghuichao 14-May-15 12:10pm    
the website just used for internal network only, I installed printer, Adobe reader server already, printer is network printer, they are in one network.
F-ES Sitecore 15-May-15 3:05am    
It's probably a permissions issue then. You'll be using the IIS anonymous user which may not have permissions to access printers etc. Try changing the anonymous user account to a domain account with the relevant printer access.
chenghuichao 17-May-15 8:52am    
I changed solutions-print before preview, there is no issue.
thank for your replies.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900