开发者

is it possible to have a link/button that directly prints a document via website?

开发者 https://www.devze.com 2022-12-08 10:35 出处:网络
is it possible to have a开发者_如何学Go link/button that directly prints a document via website?The closest you can do using normal techniques is use javascript to show the print dialog.

is it possible to have a开发者_如何学Go link/button that directly prints a document via website?


The closest you can do using normal techniques is use javascript to show the print dialog.

This limitation is built into the system, and is designed to protect users like you from spammers who dream of turning your printer into another fax machine spam target. To get around it you have to dip into the world of third party plugins.


Assuming you do not need to present a printer-friendly version of the page and just want to trigger the 'Print' function of the browser, just to this:

<input type="button" value="Print" onclick="window.print();" />

or using webcontrol button

<asp:button id="button1" runat="server" onclientclick="window.print(); return false;" text=Print" />


You may need to write Applet, Flash, ActiveX Components for this.

Please note also that:

ActiveX Component only works on Windows(mostly IE).
Applet/Flash may work on major OS such as Windows/MAC/Linux

I suggests you go with Applet though the client should need JRE installed.


Yes, simply call the javascript "window.print()" on the link or button.

i.e.

Edit: Saw your other comment about wanting to print Office documents. Your only options here are to either open the document using the native app, or convert to HTML or PDF server side.

As another posted pointed out, you could potentially embed an ActiveX object, but this causes all sorts of security issues and would be unlikely to work in the default IE security settings, and not at all on other web browsers.

If you are working in an Intranet, you could potentially have the server connect to the office printer directly, but other than this I'm afraid there's no real way to do it without significant caveats. I recommend just provide the user with a download, and let them print it themselves.


I think you may need to read complete document which is to be print with the help of some sort of library which reads whole document as text/html into memory stream and write to output stream, finally call the window.print();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号