Direct print without preview with asp.net/javascript

0

I'm trying to print directly to a default printer. What I do is send print with preview, because for now I can not print directly, because when uploading it to production site I got errors that according to some answers to my question, was that for security you can not send a process of print from the server to the client's PC ( How to print a document without preview, using the production site from the client? )

My idea is that when the instruction to print is sent, the preview will be disabled or skipped, so that it can be printed directly, without asking the printer to print. I have seen that there are web applications that work correctly when printing tickets.

My code is as follows:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type = "text/javascript">
            function PrintPanel() {
                var panel = document.getElementById("<%=pnlContents.ClientID %>");
                var printWindow = window.open('', '', 'height=400,width=800');
                printWindow.document.write('<html><head><title>DIV Contents</title>');
                printWindow.document.write('</head><body >');
                printWindow.document.write(panel.innerHTML);
                printWindow.document.write('</body></html>');
                printWindow.document.close();
                setTimeout(function () {
                    printWindow.print();
                }, 500);
                return false;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat = "server">
        <asp:Panel id="pnlContents" runat = "server">
            <span style="font-size: 10pt; font-weight:bold; font-family: Arial">Hello,
                <br />
                This is <span style="color: #18B5F0">Mudassar Khan</span>.<br />
                Hoping that you are enjoying my articles!</span>
        </asp:Panel>
        <br />
        <asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick = "return PrintPanel();" />
        </form>
    </body>
    </html>

I hope I can find the solution to skip the preview and thus print directly without having to make any configuration in the browser

    
asked by Danilo 08.10.2017 в 19:07
source

1 answer

1

The only way to do this is to install a client desktop application that communicates with the server, that is, using signalR. The client application is installed for each box or places to be printed, if it is printed from the same box, you only need to install a client application.

    
answered by 08.06.2018 в 17:41