How to print a text (coupon) via javascript?

5

I have a commercial web application written in ASP.NET MVC4 with C #, where I need to print a direct sales closing coupon for a non-fiscal (diebold) printer.

Is there a way to send JS a direct document to the printer without printing or confirming anything?

As if I were to mount a string in JS, or get it via AJAX and print it!

    
asked by anonymous 28.10.2014 / 17:07

2 answers

3

If you want to skip the view and confirmation screens, you can not cross-browser. This is from the browser implementation. Maybe is possible with IE if you set up a printer by default - although I do not know IE in depth and can not guarantee that it is even possible - but I guarantee that in Chrome it does not give because it goes necessarily show at least the dialog where you choose whether you want to send it to a device or save it as a document.

Editing: Chrome has a kiosk mode, see Vitor Pinho's answer . However, the way kosqueque has its problems there. This solution has stopped working from one version to another before, so if you want to use it, you may need to freeze the browser version in your POS.

Javascript itself is built with this in mind. To request an impression with JS, you call the print method of the window object. So:

window.print();

In very basic terms ... This is a way for you to say to the browser: "pretend that the user pressed CTRL + P in the window where this script runs!" the print code you run is the browser code, not your code.

Otherwise, it's good practice to have a print style sheet (CSS), which is distinct from the "main" sheet of the site. This print style sheet usually removes background colors and images, headers, footers, and so on. to leave the content more suitable for printing. When printing, do not call window.print(); in the content window: open a new tab with the E content sheet, and on that new tab call window.print(); . Good luck!

    
28.10.2014 / 17:56
2

You can get it in Chrome by launching the browser in kiosk mode:

  • Create a Chrome shortcut
  • Right click on the shortcut and select properties
  • In the "Destination" field add the following command to the end (after the quotation marks): - kiosk-printing
  • Close all instances of Chrome and initialize an instance through the created shortcut
  • That way when you ask to print, the Chrome print window will not open and the print will be sent to the default printer. This is the limitation as it can only be sent to the default system printer and you can not choose another one.

        
    28.06.2017 / 15:48