2

I have a Web based POS system which needs to get information from a server and get printed client side.

I have spent 2 days searching but still i am not able to achieve what i want.

what happens is a cashier will generate a random serial number and pin which is then saved in the database, after the generation a receipt should be printed to the cashiers default printer. each cashier has there own default printer.

The printing is working exactly how it should but the Print dialog box is being shown, how would i go about printing the receipt but not displaying the Print Dialog?

i have tried many VB scripts, jquery and Javascripts. all have failed. I am printing the contents of an iFrame.

All cashiers are using Windows 7 and Internet Explorer 10.

The Following button displays the iFrame.

protected void Generate_Click(object sender, EventArgs e)
    {
        myIFrame.Visible = true;
    }

when the page loads in the iFrame Javascript is run that will print the Frames contents

protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Print", "PrintVoucher();", true);
    }

Javascript

<script type="text/javascript" language="javascript">

    function PrintVoucher() {
        window.focus();
        window.print();
        return;
    }
</script>
Confused Guy
  • 81
  • 2
  • 12
  • See if this answer (the IE part) could help http://stackoverflow.com/questions/21908/silent-printing-in-a-web-application – Steve Aug 15 '13 at 09:53
  • 1
    I wish you luck in your search but I think this is a feature that has purposefully been left out of javascript for security reasons for example think of the number or practical jokers that would abuse this and force print thousands of pages just because you visited a website – jgok222 Aug 15 '13 at 12:49
  • [It is a solved problem on stack overflow](https://stackoverflow.com/questions/9213660/html-javascript-one-click-print-no-dialogs) – Abolfazl Pourmohammad May 17 '22 at 14:22

2 Answers2

0

You should be able to use an already written ActiveX control for this. It is included in Windows and therefor free to use.

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

This will essentially overwrite the original print event that you already use. Hence if you want to print something you can just keep using

window.print();

Hope this helps.

DrkNess
  • 676
  • 5
  • 4
0

I have implemented for disabling printing using window.onbeforeprint() Refer this Answer

/*Block printing*/    
        window.onbeforeprint = (event) => {
            console.log("onbeforeprint function");
            printDiabled();
        };
    
        function printDiabled() {
            var headstr = " <span style='font-size: large; font - weight: bold; color: Red''>PRINT IS DISABLED</span>";
    
            //var oldstr = document.body.innerHTML;
            document.body.innerHTML = headstr;
        }
        /*Block printing*/
Ashi
  • 409
  • 3
  • 12