wood burning stoves
The moose likes HTML, CSS and JavaScript and the fly likes Direct Print to a Printer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Direct Print to a Printer" Watch "Direct Print to a Printer" New topic

Direct Print to a Printer

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
I've used the following code to imitate a direct print to a printer using javascript. The terminology may not be sound but the code works. Hopefully this will help someone out there looking to print to a printer "directly". If you have a better alternative approach, what keep you from getting back sooner? :
// Set the frames source, basically your HTML
// page holding the javascript will be in one
// frame while this one will hold the data to
// print. Set the javascript page to be 100%
// width and the data page frame to be 0%
var purchasetxt = print_items.arguments[0];
window.parent.frames['display'].src = purchasetxt;
//=== Obtain the data frame object
upper_object = window.parent.frames['display'];
//=== Create a Web Browser Object
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

//=== Insert the Web Browser Object into
//=== the second frame's window upper_object.document.body.insertAdjacentHTML('beforeend', WebBrowser);
//=== Set focus to the second frame (i.e. data
//=== frame)
//=== Execute the Web Browser Object upper_object.document.WebBrowser1.ExecWB(6,-1);
//=== Get rid of the Embedded Web Browser Object upper_object.document.WebBrowser1.outerHTML = "";
ric tan

Joined: Mar 16, 2006
Posts: 1

do you have a web page with this function works ?

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 832
You're lucky I noticed this cause I had another question I was looking for. Yeah, I do have a few applications that has this working on them. Mind you, the people using this normally run only IE but I do believe it has been tested on Netscape as well.
I agree. Here's the link: http://aspose.com/file-tools
subject: Direct Print to a Printer
It's not a secret anymore!