views:

841

answers:

4

I would like to send a print job to the printer without the user having to click "okay" on the print confirmation dialog window.

Either C# code-behind or javascript would be fine, whichever works better.

So... I know it it possible to print an HTML document, but is it possible to print without the user clicking okay?

  • The reason I ask this is because the print job prints off a document 100 times, dynamically inserting form values. (Imagine you were printing off a thank you card to 100 people, and didn't want to change the name yourself 100 times). If the user has to confirm the print job for each of these document, it's going to take a while to finish just one print job. Now imagine if 100 print jobs came in in one day! That's one person spending hours just to click "okay" 10000 times.

Note: It's only one person who's going to need to use the printing form, so if it's a matter of lowering security issues in the browser that would work. I just need a way to allow all 100 prints to go through without confirmation of each one (even just 1 confirmation per 100 would be fine, but the document still has to change each time).

+3  A: 

From any major browser -- I'm pretty sure you can't.

You could create a WinForm app that has a WebBrowser control embedded in it and print from there without user confirmation (if I remember correctly, there is a Print method off the object).

Austin Salonen
And thank God for browsers not allowing that! Just imagine the junk your printer would be spewing out if the ad-agencies got wind of this...
Ruben
I completely agree. It would just be nice if it was a security thing that you could turn off if need be...
Matt
+1  A: 

If you are using Internet Explorer 5.5 or later, this should work:

function printit(){ 
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(6, -1); 
    WebBrowser1.outerHTML = ""; 
}
Robert Harvey
...What does it do?
Matt
Essentially the same thing that Austin's suggestion would do. The OBJECT reference is the WebBrowser control. The InsertAdjacentHTML command gets the page content. ExecWB(6, -1) is what executes the Print command without prompting.
Robert Harvey
+1  A: 

Why not create a single page with all 100 cards and print that, just ensure you have appropriate page breaks.

KeeperOfTheSoul
+2  A: 

I found this question as I was looking for a solution to this problem, and I post it here at least for my own reference. It can be done quite simple in Firefox (tested with v. 3.5):

  • Go to about:config in the address bar of Firefox
  • Right click on the first setting, go to new -> boolean -> add "print.always_print_silent" -> value "true"
  • Restart Firefox

Now if you call window.print() from javascript the page gets printed out without prior confirmation.

Source: http://forums.mozillazine.org/viewtopic.php?f=40&amp;t=48336&amp;start=0

Max
Thanks a lot for this trick, it's perfect for the project I'm working on !
Zed-K