asp.net网站打印pdf文件到本地网络打印机问题

问题描述:

我在asp.net网站上使用以下代码打印PDF文件

Im using below code for print PDF files in asp.net 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;
process.Start();



我只是想在本地网络打印机中打印文件,而无需预览。在我的本地计算机(开发环境)中它工作正常,但在发布到本地服务器(Windows 2008)后,此功能无法正常工作。



任何人都可以帮助或给予一些建议?


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?

它在本地工作,因为客户端和服务器是同一台机器,服务器代码可以访问客户端资源。部署后,服务器和客户端不再是同一台计算机。您无法从服务器代码访问客户端资源,无法使用服务器代码打印到本地打印机。您可以在客户端上使用window.print,这将触发您无法避免的打印确认对话框。



想一想....打印成本金钱,您是否希望网站在没有您干预的情况下打印到您的打印机?
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?