Print without confirmation window in PHP, Javascript or Ajax

I have a non-tax Zebra TLP 2844 thermal printer, and I am developing a password generation program to print on that printer.

I'm using the printer_ functions.

I tried the following example code:

<?php
   $handle = printer_open();
   printer_write($handle, "Testando...");
   printer_close($handle);
?>

But it is not printing the text of the "printer_write". What can I be doing wrong?

I need to print without opening the printer choice window, so I thought about this method. Could someone point me another one?

Author: Bacco, 2014-09-14

3 answers

In Firefox it is a matter of setting up print.always_print_silent:

  • put in the URL bar: about:config
  • search for this config and Mark as true
  • if it does not exist, right-click and ask for " new "- > "Yes/No", adding the config name and the value
  • after that, the JS window.print() goes straight to the printer without the confirmation dialog

For FF, it also has this add-on:

JS Print Setup
client side Javascript printer settings. This extension implements print setup from CS Javascript, similar of Meadco's ScriptX ActiveX control for Internet Explorer.

In Internet Explorer, apparently it is possible to use VisualBasic :

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

References:

 4
Author: brasofilo, 2017-05-23 12:37:34

It seems that you missed starting the print job.

Example:

<?php    
    //$handle = printer_open("HP Deskjet 930c");  // http://php.net/manual/pt_BR/function.printer-open.php
    $handle = printer_open();

    printer_start_doc($handle, "Document name");        
    printer_start_page($handle); // Start page 1
    // here goes the content of page 1 via printer_write
    printer_write($handle, "A37,503,0,1,2,3,N,PRINTED USING PHP\n");
    printer_end_page($handle); // Close page 1

    //printer_start_page($handle); // Start page 2
    // here goes the content of page 2 via printer_write
    //printer_end_page($handle); // Close page 2

    printer_end_doc($handle);
    printer_close($handle);
?>

Source: https://stackoverflow.com/a/24217694/194717

 2
Author: Tony, 2017-05-23 12:37:23

Try jzebra (qz-print), to send direct commands to the printer.

Https://code.google.com/p/jzebra /

Example Of Use:

<input type=button onClick="print()" value="Print">
<applet id="qz" name="QZ Print Plugin" code="qz.PrintApplet.class" archive="./qz-print.jar" width="100" height="100">
      <param name="printer" value="zebra">
</applet>

<script>
      function print() {
         var qz = document.getElementById('qz');
         qz.append('A37,503,0,1,2,3,N,PRINTED USING QZ-PRINT\n');
         // ZPLII
         // qz.append('^XA^FO50,50^ADN,36,20^FDPRINTED USING QZ-PRINT^FS^XZ');  
         qz.print();
      }
</script> 
 1
Author: Tony, 2014-09-14 21:11:06