25

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.

Ramiz Uddin
  • 4,259
  • 4
  • 35
  • 71
  • I had already preassumed that such an option would be possible for IE by making an activeX control. But didn't remember that this could also be done through vbscript. Got Lucky and found this: http://msdn.microsoft.com/en-us/library/ms976105.aspx I haven't tried it yet but this gives me a helpful reminder look this could save me to gets my hand dirty from activeX – Ramiz Uddin Jul 08 '09 at 10:16
  • I know this thread was super old. But maybe someone try to find out, please check this : https://github.com/apinprastya/pulas – Apin Jul 21 '16 at 23:34
  • Some other browser printing solutions are available here: http://stackoverflow.com/a/28783269/3196753 – tresf Sep 20 '16 at 05:56
  • To chrome browser, you can do this: `` – Marinpietri Feb 01 '20 at 14:12

7 Answers7

18

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
  • 4,259
  • 4
  • 35
  • 71
  • 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 Sep 14 '10 at 15:48
  • @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 Oct 23 '10 at 20:49
  • the variables you refer to are just constants. They should work the same in Javascript. – Jordão Oct 24 '10 at 00:04
  • Is there a way to possibly print a page in an iframe with this method? –  Apr 02 '15 at 04:27
  • 2
    Does this still work? I tried it and I received a prompt. – Eric Wiener Feb 06 '17 at 01:19
  • I verified in IE11, getting print dialogue. – vasuy19 Mar 07 '17 at 06:25
  • This works perfect in IE. but in chrome again it shows print dialog box – Srinivasan Jul 14 '17 at 00:04
  • no luck on this script, I tried on IE 11, The print dialog prompts – Naz141 Jul 22 '18 at 05:55
  • You can do using a extension for chrome,: https://chrome.google.com/webstore/detail/chrome-direct-print/fnfkcaeloalplnglklappfjfjeafakeo – Marinpietri Jul 15 '20 at 00:53
3

IE9 no longer supports triggering the Print() VBScript by calling window.print() like IE7 and IE8 do, and thus window.print() will now always trigger the print dialog in IE9.

The fix is pretty simple. You just need to call Print() itself, instead of window.print() in the onclick event.

I've described the fix in more detail in an answer to another question, with a working code example sporting slightly updated HTML syntax (as much as possible while still tested as working code).

You can find that sample code here:

Bypass Printdialog in IE9

Community
  • 1
  • 1
purefusion
  • 932
  • 1
  • 14
  • 23
3

AttendStar created a free add-on that suppresses the print dialog box and removes all headers and footers for most versions of Firefox.

https://addons.mozilla.org/en-US/firefox/addon/attendprint/

With that feature on you can use $('img').jqprint(); and jqprint for jquery will only print that image automatically called from your web application.

Jon
  • 2,176
  • 2
  • 16
  • 19
1

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
  • 1,200
  • 8
  • 15
  • 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 Jul 08 '09 at 09:32
  • 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 Jul 15 '09 at 03:49
  • 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 Jul 15 '09 at 23:06
  • 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 Jul 22 '09 at 05:24
0

this.print(false);

I tried this in Chrome, Firefox and IE. It works only in Firefox and IE, it uses the default printer (with default print settings) and only works when I render a PDF (I use Foxit Reader with Safe Reading Mode disabled). Chrome shows the print dialog, also the other browsers when I render an HTML page.

DannyC
  • 1
  • 1
0

For IE browsers, the "VBScript solution" works.

But as mentioned by @purefusion at Bypass Printdialog in IE9, Use Print() rather than window.print()

Community
  • 1
  • 1
pprain
  • 83
  • 7
-3

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);
sth
  • 200,334
  • 49
  • 262
  • 354
Maddy
  • 3
  • 1
  • there is no print() method available in java script with boolean parameters. – Gunjan Shah Apr 19 '13 at 05:37
  • Even if you could do this, for proprietary reasons I would not implement. Unless its a specific application used at work by a specific subset of people. Even if, imagine if my printer were to automatically print just by visiting a page and with no confirmation as to what I wanted to print. 1. I would think that there's a possible virus as I wasn't even asked if I wanted to print. 2. I would waste countless paper on peoples machines. What if they wanted only 1 page out of a 15 page report. END LESSION: Printing should not be done without going through printing protocols. – Spoo Mar 13 '14 at 20:37