Printing our web pages is an integral part of web development. How you do it, however, is restricted due to security reasons.
The standard way to print a web page in Internet Explorer 5.0+ and Netscape Navigator 4.x + is to use the Document Object Model’s command window.print(). You can call this from a button onclick event, or even have this command fire on a window_onload event. In fact, you can choose to fire it whenever you desire.
Keep in mind, you really cannot do this in ASP (since then you’d be sending the document to the server’s printer!). Remember, this is only a client side command. If a reason ever arises that you need to print to your server’s printer, perhaps for some type of reports, you can easily write a VB COM object that can print it for you.
So we’ve established that you want to print a page on the client’s printer. The one thing you cannot do, is bypass the printer dialog option. This is done for security reasons. Let’s say you happen on to my site by doing a search on Google. In my window_onload event, I send 40 pages of advertisements to your printer, without your permission. Using your ink. Using your paper. I think it goes without saying you would be quite upset, eh?
Unless you’re willing to write your own Active X control to bypass the dialog (and doing so would scare most of your Internet customers from downloading it), you’re stuck with the dialog box. No exceptions.
If you’re attempting to change the orientation of the printed pages (i.e., form portrait to Landscape), you may want to check out a few of the CSS properties, such as the @Media tag or the @Page, though I could never get these objects to work successfully. I found the old standby of popping up an alert box one time to warn the user to print in landscape mode is sufficient.
Remember when sending pages to your client’s printer, you should be nice and try to keep the graphics to a minimum. You may also want to use a separate “print page” like 4guys has. Find out how to do that here.