How to print directly without opening the browser dialog box?

Asked

Viewed 2,344 times

4

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

  • Matricial MP-20 MI Non Tax Printer - For the Non Tax Coupon;
  • Zebra TLP 2844 Non Tax Thermal Printer - For Label;

I even managed to print using the DLL php_printer PECL with php, but it wasn’t working the way I needed it: the print hangs, sometimes sends and doesn’t print anything. It’s pretty unstable!

I tried to make use of the library escpos-php and the Matrix printer worked correctly, but the Zebra printer does not print the text I send.

Vi that it is possible to perform a configuration in the browser (Firefox only) 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, according to 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 make this impression with PHP, Node.js or javascript?

  • 1

    If it were a "common" printer there is the "print" command of Windows itself, which could run with "exec()", it would be something like exec("PRINT [/D:device] [[drive:][path]filename[...]]");, I couldn’t find an official documentation link. There may be some other CLI software for printing more complex documents, such as http://www.doc2prn.com/, I have never tested, but only one example.

  • window.print(); doesn’t solve?

  • No, yeah window.print() will open the browser print pattern screen.

  • Seria CTRL SHIFT P?

2 answers

5


Direct response: No, it’s not possible.

Imagine it was possible, you visit a website unintentionally start printing unwanted things on your printer without your permission, already imagined?

Who commands the printing is the browser, 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, i.e., have it printed on a printer that is connected to the server-side, but printing on the client-side without permission is not possible.

You need to understand the difference between server-side and client-side. php is interpreted in server-side and shown for the client-side. Print using a command shell or exec will command in the server-side.

-2

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 Voce browser tab sends a pro socket command, where the nodejs will listen, when reading the message, print.

Browser other questions tagged

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