How to print directly without opening the browser dialog box?

I am developing a web system where I need to print a label and a non-tax voucher after submitting a certain form. To perform this action, I have two printers:

  • MP-20 Mi Matrix non - tax printer-for the non-tax coupon;
  • thermal printer zebra TLP 2844 not tax-for the label;

I even managed to do the printing using the DLL php_printer of PECL with php, but it was not working the way I needed: printing hangs, sometimes sends and does not print anything. It's very unstable!

I tried to use the library escpos-php and in the matrix printer worked correctly, but in the Zebra printer it does not print the text I send.

I see that it is possible to perform a configuration in the browser (only Firefox) so that the user can print without opening the dialog box, but for this the user needs to perform a configuration in the browser and it is possible to use only one printer and not two, as my need.

For compatibility reasons I cannot have a java applet on the machine.

I cannot use VBScript or ActiveX, as I cannot force the user to use only a specific browser.

Is there any other way to do this printing with PHP, Node.JS or javascript?

Author: Adriano de Azevedo, 2016-09-19

2 answers

Direct answer: No, not possible.

Imagine if it were possible, you visit a website unintentionally start printing unwanted things on your printer without your permission, have you ever imagined?

Who runs the print is the browser, it is client-site, PHP has nothing to do with it. Unless you want to command something to print on the server-site, which is where PHP runs, that is, Have It print on some printer that is connected to the server-side server, but, printing to client-side without a permission is not possible.

Need to understand the difference between server-side and client-side. Php is interpreted in the server-side and shown to the client-side. Sending print via a command shell or exec will command on the server-side.

 5
Author: juniorb2ss, 2016-11-09 15:40:01

You can print directly from a browser tab if:

  • you have a direct communication interface with the printer, example:
    • a nodejs with a client socket connected to a socket on a cloud host.
    • a nodejs with serialport and connected with the printer.
  • from the browser tab you send a pro socket command, where nodejs will be listening, when reading the message, prints.
 -2
Author: Felipe Marques, 2020-12-29 02:55:03