Printing with JavaScript and ActiveX

0

I need to print from a web application, I believe that I will have to do this with JavaScript and also for what I researched maybe I will have to do this with ActiveX.

I already tried to use window.print() with JavaScript but it opens that window asking to choose the printer, in my case printing has to be done directly, without user interaction.

How to do this?

    
asked by anonymous 30.07.2015 / 04:17

1 answer

1

On the standard web you can not do this. I'll tell you more about this on this answer .

With ActiveX it is possible but it only runs in Internet Explorer, a browser at the end of the line. The new browser from Microsoft is Edge, which will make IE receive much less attention, or even be almost abandoned.

Certainly there are other plugins to resolve the issue in other browsers , but it's something so complicated that it's not worth the effort. Remembering that it is rare for someone to install something just to access a site . People are already revolting themselves from having to install Java to access their bank.

An applet Java could do the same but trying to use what was stated in the question:

<!DOCTYPE html>
<html>
<head>
    <title>Print Test</title>
    <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>
</head>
<body>
    <object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object>
    <a href="#" onclick="Print()">Clique aqui para imprimir</a>
</body>
</html>

Retired from this answer in the SO .

    
30.07.2015 / 04:35