This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes Printing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Printing" Watch "Printing" New topic
Author

Printing

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
I have checked this topic out before posting this and I have found nothing relevant to what I'm trying to do. I have a main page that (upon clicking a button) opens another window with another HTML in it. I want to send the contents of this other HTML document (i.e. the one in the new window) directly to a printer. This application is not running over the web but, rather, is running locally on an intranet. I've used the print() method to try printing to the printer but that comes up with the print dialog box and I don't want that. I know at one point before, the print() method (in IE) did print to the printer and then closed. I had a close() method inserted shortly after the window print() method was called and that closed the window and the print was called. Now, the same scenario doesnt occur. After the print method is called the dialog stays up.
Is there a way to directly call the same code as what is called by the browsers print button and not the print option under file?
Would WSH be the best alternative?
Is there any other options available here?
Thanks in advance for any response.
Rob
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Hi, there is a link, that solves your problem.
It is Windows IE only, and I tryed it in my IE5.5:
http://www.faqts.com/knowledge_base/view.phtml/aid/9169
This is the code I tryed:
<SCRIPT LANGUAGE="JAVASCRIPT">
function ieExecWB( intOLEcmd, intOLEparam )
{
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
if ( ( ! intOLEparam ) || ( intOLEparam < -1 ) || (
intOLEparam > 1 ) )
intOLEparam = 1;
WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
WebBrowser1.outerHTML = "";
}
</script>
<button on_Click="ieExecWB(6, -1)">
Print Me! - No Prompt!
</button>
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
Hi Yuriy,
Thanks for the response but I have already tried code similar to that and it didnt work. Before I tried to open the new window and then a print() and then a close() (if it were IE). It had worked at one point (eons ago) and now it doesnt. I have an HTML page for a bunch of things and depending on certain conditions a different page will print so I was hoping, first of all, to send the contents of the page 'directly' to the printer but that doesnt seem easily possible. So when I use :
new_win = window.open(.... does the code you posted still work for the new page just opened? I mean new_win.document. and then whatver objects. If this doesnt seem like something meant for javascript in this way do you know anything about WSH? I understand that things are a bit diificult over the web but this is a local application so I knew there have to be ways to accomplish this. Thanks so much for the help. Hopefully you have another idea on the tip of your brain. Thanks again.
Rob
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Is this page, that you want to print, yours, or it is just taken from internet? Is it in the same domain?
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
Hi Yuriy,
The computer running this application will not have access to the outside world, probably not even the local network.
Rob
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 818
Hi Again,
Sorry I misunderstand where the app was going. The application will be running on a server about 4-6 computers on the network will be running this application. Each computer will have its own printer connected and therefore will need to print to its own printer. I've tried the code posted by Yuriy above and it seems to work fine but it appears that the page prints to the printer attached to the server. This printer is indeed shared and added to the printer group of every printer in question but the default printer is set up as the printer directly connected to each computer. Am I leaving something out here? Any help would be GREATLY appreciated. Thanks.
Rob
 
wood burning stoves
 
subject: Printing