There is a web application on ASP.NET (c #). To work on the kiosk (touch terminal), a printer is connected to the terminal. You must call the printing of a web page from an application without a printer selection dialog box (default printer).

I found this solution:

<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> 

VBScript does not work and swears on the ExecWB method. I am not strong in vbscript, I need a similar solution to c # + javascript.

And the fact that at the IE5 kiosk adds a spoonful of tar to it ... Please help me figure it out ...))

  • and where is your ASP.NET? put <object into markup (remove document.write) - Konst
  • asp on a web page, I did not make it here. The link <a href="javascript:window.print();"> Print </a> is directly on the form. Tried to endure. When you click on the button, the project crashes with the error "WB.ExecWB method is not supported." I conclude that this part is needed not on VBScript, but on Sharpe to implement ... - Irina Ugryumova
  • Probably not IE5, but someone forgot in the html-document to put doctype. - Qwertiy
  • No, there is a doctype. The document begins like this: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Receipt.aspx.cs" Inherits = "Receipt"%> <! DOCTYPE html> - Irina Ugryumova
  • In the generated page, <!DOCTYPE goes at the very beginning without spaces, line breaks and BOM? - Qwertiy

4 answers 4

Connect to the project build Microsoft.mshtml.dll

 var wb = new WebBrowser(); // ... var doc = wb.Document as mshtml.IHTMLDocument2; doc.execCommand("Print", true, 0); 

and if you need to call from javascript on a web page, then:

 document.execCommand('print', false); 
  • Thanks for the answer! I understand correctly: in order for me to call on the client a print to bypass the dialog, do the following: connect the Microsoft.mshtml.dll assembly to the project and call the Print button handler - document.execCommand ('print', false) ;? On the server side, there will not be anything to add? - Irina Ugryumova
  • What do you have on the client? if the program is in c #, then - yes (it is necessary to connect mshtml to the project), and if the web page, then - no. - Stack
  • I have a web page - Irina Ugryumova
  • means option for javascript. Before the </body> code of the page add <script>function print() { document.execCommand('print'); }</script> <script>function print() { document.execCommand('print'); }</script> and call print () when the button is clicked. - Stack
  • added the specified code. Printer selection window still appears - Irina Ugryumova

If it is possible to use chrome (ium), then:

http://peter.sh/experiments/chromium-command-line-switches/

 --enable-kiosk-mode --kiosk-printing 
  • thanks, but only IE and only version 5 .. ( - Irina Ugryumova

print.js

 // The code by Captain <cerebrum@iname.com> // Mead & Company, http://www.meadroid.com/wpm/ // fake print() for IE4.x if ( !printIsNativeSupport() ) window.print = printFrame; // main stuff function printFrame(frame, onfinish) { if ( !frame ) frame = window; if ( frame.document.readyState !== "complete" && !confirm("The document to print is not downloaded yet! Continue with printing?") ) { if ( onfinish ) onfinish(); return; } if ( printIsNativeSupport() ) { /* focus handling for this scope is IE5Beta workaround, should be gone with IE5 RTM. */ var focused = document.activeElement; frame.focus(); frame.self.print(); if ( onfinish ) onfinish(); if ( focused && !focused.disabled ) focused.focus(); return; } var eventScope = printGetEventScope(frame); var focused = document.activeElement; window.printHelper = function() { execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript"); printFireEvent(frame, eventScope, "onafterprint"); printWB.outerHTML = ""; if ( onfinish ) onfinish(); if ( focused && !focused.disabled ) focused.focus(); window.printHelper = null; } document.body.insertAdjacentHTML("beforeEnd", "<object id=\"printWB\" width=0 height=0 \ classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>"); printFireEvent(frame, eventScope, "onbeforeprint"); frame.focus(); window.printHelper = printHelper; setTimeout("window.printHelper()", 0); } // helpers function printIsNativeSupport() { var agent = window.navigator.userAgent; var i = agent.indexOf("MSIE ")+5; return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0; } function printFireEvent(frame, obj, name) { var handler = obj[name]; switch ( typeof(handler) ) { case "string": frame.execScript(handler); break; case "function": handler(); } } function printGetEventScope(frame) { var frameset = frame.document.all.tags("FRAMESET"); if ( frameset.length ) return frameset[0]; return frame.document.body; } 

form.asp

 <script language="javascript" type="text/javascript"> function Print(){ with(document.myform) { target = 'printHiddenFrame'; action = 'report.asp'; submit(); target = ''; action = ''; } } function onprintHiddenFrame() { if (printHiddenFrame.document.readyState=="complete" && printHiddenFrame.location.href != 'about:blank') printFrame(printHiddenFrame); } 

 <iframe name=printHiddenFrame width=0 height=0 onreadystatechange="onprintHiddenFrame()"> </iframe> 
  • First, it's some kind of creepiness. And secondly, how is this code associated with the dialog box? - Qwertiy

Thanks to all! The issue is resolved! I had to make a small feint with my ears. Previously, this web application on the kiosk was launched using an HTA application. In this case, it was necessary to be content only with the capabilities of the default browser.

Now, instead of hta, an application is written on Windows Forms (c #), in which the WebBrowser component lies and on top of the invisible "Print" button. The required page is loaded into the component, the "Print" button appears and when you click using the webBrowser1.Print() function, the page immediately flies to print to the default printer.