使用 C# 将文档发送到打印机 [英] Send document to printer with C#

查看:75
本文介绍了使用 C# 将文档发送到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求使用内部 Web 应用程序透明地将文档发送到打印机.这个想法是用户可以选择离他们最近的打印机,Web 应用程序会将他们的打印作业发送到他们选择的打印机.

I've been given a requirement for an internal web application to send documents to a printer transparently. The idea would be that the user can select their nearest printer, and the web application would send their print jobs to the printer they selected.

我们必须推出的第一台打印机是佳能,所以我的问题是:我如何将要通过网络打印的文档发送到特定的佳能?Cannon 的问题是 iR5570,要说的文档主要是 Word 和 PDF

The first printer we have to roll out against are Canons, so my questions is: How would I go about sending a document to print aross the network to a specific Canon? The type of Cannon is question is an iR5570 and the documents that will be said will mainly be Word and PDFs

我目前正在浏览这个糟糕的、仅限 IE 的佳能开发者网站,但我有点希望有人能指出我正确的方向或将我指向第 3 方大会:)

I'm currently working my way through the terrible, IE only Canon Developer site, but I'm kinda hoping someone can point me in the right direction or point me at a 3rd party assembly :)

推荐答案

该问题中的关键词是Web 应用程序".

The key phrase in that question is 'web application'.

在仅通过 HTTP 使用 HTML+Javascript 的普通 Web 应用程序中,您不能只是将文档直接发送到打印机.这就是网络浏览器存在的原因之一,如果没有该功能,每个人的打印机都会像公共传真机一样收集垃圾.

In a normal web app using only HTML+Javascript over HTTP, you can't just send a document directly to a printer. That's one of the reasons web browsers exist, and without that functionality everyone's printer would collect the same kind of junk that a public fax machine does.

所以你需要一些变通办法.一种选择是建立在一个通用插件上,比如 flash、silverlight、java applet,甚至是像greasemonkey 之类的东西.另一个是自定义插件,如托管的 winforms 控件或自定义浏览器扩展.

So you need some kind of work-around. One option is to build on a common plug-in, like flash, silverlight, java applet, or even something like greasemonkey. Another is a custom plug-in, like a hosted winforms control or custom browser extension.

您非常幸运,因为您似乎完全控制(或了解)部署环境,而且该环境相当同类.这意味着您有其他人已经开始探索的附加选项.如果您可以将环境中的所有打印机安装到 Web 服务器,那么使用内置的 .Net 打印机类(在 System.Drawing.Printing 命名空间中)列出这些打印机是相当容易的打印机,或者将它们显示给用户,以便他们可以选择或保留某种 IP 到打印机的映射表,然后从您的 Web 应用程序直接打印到该打印机.请注意,此方案可能要求您的应用以比其他方式所需的更高的信任级别运行.

You are very fortunate, in that it looks like you have complete control (or knowlege of) the deployment environment, and that this environment if fairly homogenous. This means you have an additional option that others have started to explore. If you can install all of the printers in your environment to the web server, then it's fairly easy using the built-in .Net printer classes (in the System.Drawing.Printing namespace) to list out those printer, either show them to the user so they can pick or keep some kind of IP to Printer mapping table, and then print directly to that printer from your web app. Note that this scheme may require your app to run at a higher level of trust than would otherwise be required.

现在开始实际打印您的 PDF 和 Word 文档.对于 acrobat,请查看此链接:
http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm(Wayback 机器)
请注意,它有点过时了,但我相信这个概念仍然有效.您必须进行一些试验以确保它按预期工作.

Now it comes to actually printing your PDF's and word documents. For acrobat, check this link:
http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm (Wayback machine)
Note that it's a little dated, but I believe the concept is still valid. You'll have to experiment some to make sure it works as expected.

对于 Word,我通常不喜欢 Web 应用程序中的 Office 互操作/自动化.但在这种情况下,您没有编辑任何文档:只需加载足够长的时间即可打印.并且您依赖另一种稀缺资源(打印机)的事实应该防止其扩展到超出您的 Web 服务器可以处理的范围.因此,您可能会遇到 Web 项目中的 Office 自动化有意义的罕见情况.

For Word, I'm not normally a fan of Office interop/automation in a web app. But in this case you're not editing any documents: just loading it up long enough to print. And the fact that you're relying on another scarce resource (the printers) should keep this from scaling beyond what your web server could cope with. So you may have a rare case where Office automation in a web project makes sense.

这篇关于使用 C# 将文档发送到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆