Print without confirmation window in PHP, Javascript or Ajax

1

I have a non-fiscal Zebra TLP 2844 thermal printer, and I'm developing a password generation program to print on this printer.

I'm using the printer_ functions.

I tried the following sample code:

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

But you are not printing the "printer_write" text. What can I be doing wrong?

I need to print without opening the printer's choice window, so I thought of this method. Could someone tell me another one?

    
asked by anonymous 14.09.2014 / 22:23

3 answers

4

In Firefox it's a matter of setting 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 value
  • After that,% s of% goes straight to the printer without the confirmation dialog

For FF, you also have this add-on:

  

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

In Internet Explorer, it's apparently you can 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:

14.09.2014 / 23:45
2

It looks like you were missing 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: link

    
14.09.2014 / 23:27
1

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

link

Example usage:

<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> 
    
14.09.2014 / 23:11