C# 从 Web 应用程序打印到客户端打印机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/206880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:03:16  来源:igfitidea点击:

Printing to a client printer from a web app

c#.netasp.netjavascriptprinting

提问by Jeremy

If I have a printer hooked directly to a pc (a kiosk with a printer), how would I go about creating the ability for a web page (.net web app) to print a jpg to the kiosks printer with no user intervention other than clicking a button on the page?

如果我有一台打印机直接连接到电脑(带有打印机的信息亭),我将如何创建网页(.net web 应用程序)在没有用户干预的情况下将 jpg 打印到信息亭打印机的能力,除了单击页面上的按钮?

采纳答案by quick_dry

if you created an application that hosted the web browser control (rather than using a web browser directly) you could control the printing process much more directly.

如果您创建了一个托管 Web 浏览器控件的应用程序(而不是直接使用 Web 浏览器),您可以更直接地控制打印过程。

(assuming using Windows + IE is possible)

(假设可以使用 Windows + IE)

here are some example articles that might help:

以下是一些可能有帮助的示例文章:

Configure a WebBrowser Control

配置 Web 浏览器控件

Using the Web Browser Control in your C# Applications

在 C# 应用程序中使用 Web 浏览器控件

and the ever changing MSDN docs for the WebBrowser class, which has the Print method.

以及不断变化的 WebBrowser 类的 MSDN 文档,它具有 Print 方法。

From the print method remarks: "You can use this method to implement a Print button similar to the one in Internet Explorer. This method prints the current document without requiring further user input."

来自打印方法的评论:“您可以使用此方法来实现类似于 Internet Explorer 中的打印按钮。此方法无需进一步的用户输入即可打印当前文档。”

回答by Joel Coehoorn

This has been asked several times already, and the result is always that you can'tdo it via normal web technologies (HTML + Javascript). The best you can do is open the print dialog, and that is by design. What you can do since you control the kiosks is create some kind of browser extension (like a flash object, .Net hosted control, java applet, etc) and make that available to your page, so that it handles the printing part for you.

这已经被问过几次了,结果总是你不能通过普通的网络技术(HTML + Javascript)做到这一点。您能做的最好的事情就是打开打印对话框,这是设计使然。由于您控制信息亭,您可以做的是创建某种浏览器扩展程序(如 Flash 对象、.Net 托管控件、Java 小程序等)并将其提供给您的页面,以便它为您处理打印部分。

回答by Zote

I solve this problems in 2 different ways:

我用两种不同的方式解决这个问题:

  1. Using ActiveX
  2. Creating a protocol like myprint://PRINT_DATA
  1. 使用 ActiveX
  2. 创建像 myprint://PRINT_DATA 这样的协议

回答by Jason Kealey

The other comments cover a scenario where you want to print on the computer of the web browser.

其他评论涵盖了您想要在 Web 浏览器的计算机上打印的场景。

However, if you want to print to a printer connected to the web server (ie, the machine running the web application), you can use regular C# printing with the following twist: http://support.microsoft.com/kb/184291/

但是,如果您想打印到连接到 Web 服务器的打印机(即运行 Web 应用程序的机器),您可以使用具有以下扭曲的常规 C# 打印:http: //support.microsoft.com/kb/184291 /

In my context, my kiosk runs both the web server and the web browser, so that solved my problem.

在我的上下文中,我的信息亭同时运行 Web 服务器和 Web 浏览器,因此解决了我的问题。