How to enable direct printing capabilities for web based application?
I'm developing a web application where user require to print a particular form with a single click. Based on my findings I understand that we need to create a printable version of the form and then send it to the printer.
But still I could not find out a way to send such printable version of th开发者_StackOverflowe form directly to printer without displaying the generated form to user. Appreciate any suggestions from you.
Thank You
This is the code you need:
<img src="print_button.jpg" onClick="window.print()" alt="Print this page" style="cursor: pointer;">
You will also need to make a print css file that will style the printed page and to put this in the header:
<link rel="stylesheet" media="print" type="text/css" href="print.css" />
That should take care of what you need.
I do this by loading the print view into a hidden iframe and issuing the .print()
javascript command
If you can print from the server to a designated printer (i.e., you're in an intranet), you can do something like this. There's more code than you want to see here -- get the full code here. The key is that you nave a network printer configured with permissions for ASPNET (or the account it's running under) to print to it.
I have done this. In fact, we were printing so much that we moved the printing from the web server to a web service or Windows service on another machine, to get the load off the web server.
using System.Drawing.Printing;
using System.Text;
using System.Web;
using System.IO;
PrintDocument doc = new PrintDocument();
// set the printer name
doc.PrinterSettings.PrinterName = printerName;
// print the page
doc.Print();
精彩评论