views:

2983

answers:

4

Hi Everyone,

As it said in the subject I've to create a feature for a web-based application that will allow users to send print directly without prompting any dialog boxe just make the print i.e click and print, simple! but not for me :(.

Please, suggest what would be the best option and how should I write it up (technology).

Suggest please!

Thanks.

EDIT: The print should be send on the user's default printer.

A: 

I don't believe this is possible. The dialog box that gets displayed allows the user to select a printer to print to. So, let's say it would be possible for your application to just click and print, and a user clicks your print button, but has two printers connected to the computer. Or, more likely, that user is working in an office building with 25 printers. Without that dialog box, how would the computer know to which printer to print?

Zachary Murray
How about ActiveX control for IE that will send a print on the user's default printer. This looks a pretty doable. But, invest hours of effort to create such an activeX is not justified to provide feature for only IE users.
Ramiz Uddin
Zachary, the above script send a print command on a default printer machine without showing any popup window. But this is for IE only. I hope this will answer the doubts we had :)
Ramiz Uddin
Oh wow, I didn't even think to use VBScript. Great going, Ramiz. If you're only using IE, then you are completely set :D
Zachary Murray
Thanks. The search is still on as there are long list of browsers and this need to be done in all. But, IE was on a higher priority so a bit relaxed.
Ramiz Uddin
+2  A: 

I couldn't find solution for other browsers. When I posted this question, IE was on the higher priority and gladly I found one for it. If you have a solution for other browsers (firefox, safari, opera) please do share here. Thanks.

VBSCRIPT is much more convenient than creating an ActiveX on VB6 or C#/VB.NET:

<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

Now, calling:

<a href="javascript:window.print();">Print</a>

will send print without popup print window.

Ramiz Uddin
I tried to implement the exact same code in Javascript and it didn't work. Only in VBScript. Why does it work in VBScript but not in Javascript?
Jordão
@Jordao I think the above configuration variables are only members of vbscript. Here, in the above script what we mainly doing is resetting up configuration variables. This is just an instinct thought of your question.
Ramiz Uddin
@Ramiz Uddin: the variables you refer to are just constants. They should work the same in Javascript.
Jordão
A: 

Really works, you are GREAT. Mny thanks.

Zafadomexican
I'm glade you found it helpful. Vote please :)
Ramiz Uddin
A: 

This should work, I tried it by myself and it worked for me. If you pass True instead of false, the print dialog will appear.

this.print(false);

Maddy