Javascript and Activex printing

Asked

Viewed 241 times

0

I’m needing to make printing from a web application, I believe I will have to do this with Javascript and also by what I researched maybe I will have to do this with Activex.

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

How to do this?

  • Can you guarantee that the site will only run on Internet Explorer? Remembering that it is already legacy software and will have limited updates. Microsoft’s new browser is Edge. You can live with this?

  • Yes, the app will only run on IE.

  • What do you need to print? It’s some page content or files stored on the server?

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

1

In the default web it is not possible to do this. I talk more about this in that reply.

With Activex it is possible but it only runs on Internet Explorer, an end-of-line browser. Microsoft’s new browser is Edge, which will make IE get a lot less attention, or even almost abandoned.

Surely there is another plugins to resolve the issue in other browsers, but it’s something so complicated that it’s not worth the effort. Remembering that it’s rare to install something just to access a website. People are already revolting from having to install Java to access your bank.

A applet Java could do the same but trying to use what was indicated 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>

I put in the Github for future reference.

Taken from that response in the OS.

  • One detail is that I am using Asp.Net MVC, has how to use vbscript in this type of application?

  • Of course, the code generated by ASP.Net MVC can have anything you want, even invalid things in a browser.

  • @Edmarmunhoz solved or helped solve?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.