如何在ASP.NET中获取客户端打印机列表? [英] How to get client side printer list in ASP.NET?

查看:282
本文介绍了如何在ASP.NET中获取客户端打印机列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取客户端打印机列表?

我正在使用ASP.net,并且希望在客户端计算机上安装打印机,请帮助...

How to get client printer list?

I am using ASP.net and I want Printers installed on client machine, Please Help...

推荐答案

您可以使用javascript函数window.Print()
这将列出您的客户端打印机并打印页面.
以下是您可以尝试使用的代码.

You can use javascript function window.Print()
This will list you client machine printers and print your page.
Below is code that you can try yourself.

<html>
<head>
<script>
function printpage()
  {
  window.print()
  }
</script>
</head>
<body>

<input type="button" value="Print this page" onclick="printpage()">

</body>
</html>


Web应用程序无权访问客户端系统,这是有充分的理由的.想象一秒钟,这是可能的.诸如某个未知站点之类的合理用户会发现打印机或其他设备吗?这甚至听起来很吓人.

本文介绍了如何使用ASP.NET进行打印:
http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/printing-in -Asp-Net/ [ ^ ].

请注意,服务器端仅提供可打印的内容,所有打印选择,打印质量和其他选项的详细信息完全在客户端上发生,这是在客户端操作系统中设计的.这是唯一合理和安全的方法.

就我而言,就算是这种方式似乎也有点多余和干扰.我个人认为用户更了解何时打印,打印什么以及如何打印.您最好只提供易于打印的内容.前一阵子,一些特殊的可打印版本"锚很流行,但是您应该承认这并不美观,特别是在站点维护方面.更好的方法是使用CSS媒体类型.请参阅:
http://www.w3schools.com/css/css_mediatypes.asp [使用ASP.net打印到LPT1端口 [
A Web application does not have access to client systems, for a good reason. Imagine for a second that it was possible. Would any reasonable user like that some unknown site could discover printers or other equipment? This even sounds scary.

This article explains how to print using ASP.NET:
http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/printing-in-Asp-Net/[^].

Note that the server side only provides printable content, and all the detail of printing selection, printing quality and other options totally happens on the client side, in a way designed in client''s OS. This is the only reasonable and safe way.

Even this way seems to be a bit too redundant and intrusive, to my taste. I personally think that the user knows better when to print, what to print and how. You better just provide printer-friendly content. A while ago, some special "printable version" anchors were in fashion, but you should admit that this is not elegant, especially in terms of site maintenance. Much better approach is using CSS media types. Please see:
http://www.w3schools.com/css/css_mediatypes.asp[^].

See also my past answer on the topic:
Print to LPT1 port using ASP.net[^].

—SA


否.不可能. Web应用程序对客户端计算机的硬件的访问非常有限.最多可以调用默认打印机来弹出打印对话框.

获取打印机列表的限制是一项安全功能,因此,每当用户访问网站时,黑客就不应获取打印机详细信息来黑客入侵打印机以打印餐厅菜单.:)

您应该将打印选项留给用户,因为网站是您的,而不是打印机..
No.. It is not possible. A web application has very limited access to the client machine''s hardware. At the most you can call the default printer to popup the print dialog.

The limitation on getting the printer list is a security feature so that a hacker should not get the printer details to hack it to print the restaurant menus whenever a user accesses the website.:)

You should leave the choice of printing to the user because the website is yours, not the printer..


这篇关于如何在ASP.NET中获取客户端打印机列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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