¿Cómo imprimir desde PHP con un impresora de tickets?
Loterias, comanda, parlay, restaurant, loto activo, ruleta activa, facturas, etc..Configuración:
- Normalmente para linux se usa el puerto: /dev/usb/lp0 o la dirección ip de la impresora:
<?php
$printer = "/dev/usb/lp0"; // Puerto Impresora
//$printer = "192.168.1.101";// ip IMpresora
$pos = strpos($printer, ".");
if ($pos !== false)
{
//$handle = fopen($printer, "w");
$handle = @fsockopen($printer, 9100);
}
else
{
$handle = @fopen($printer, "w");
}
@fwrite($handle,chr(27). chr(64));
@fwrite($handle, chr(27). chr(97). chr(0)); //->Izquierda
@fwrite($handle, chr(27) . chr(33) . chr(8)); //negrita
@fwrite($handle,"<< PEDIDO >>");
@fwrite($handle, chr(27) . chr(33) . chr(0)); //normal
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, "holaaaaa111");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, str_pad("Num. Ped.", 10)." : 0");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, str_pad("Num. Ref.", 10)." : 123");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, str_pad("Num. Cta.", 10)." : 0");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, str_pad("Terminal", 10));
@fwrite($handle, chr(27) . chr(33) . chr(8)); //negrita
@fwrite($handle, "Prueba impresora pos 1");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27) . chr(33) . chr(0)); //normal
@fwrite($handle, str_pad("Mesa", 10)." : 123");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, str_pad("Mesero", 10)." : yomismosoy");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27) . chr(33) . chr(8)); //negrita
@fwrite($handle,"MESA: (1)/: (fondo)");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27) . chr(33) . chr(0)); //normal
@fwrite($handle, "------------------------------------------");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, "------------------------------------------");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27). chr(97). chr(1)); //->Centro
@fwrite($handle, "VTA. C/MESA");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27). chr(97). chr(0)); //->Izquierda
@fwrite($handle, "2017");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, "------------------------------------------");
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(27). chr(100). chr(1));//salto de linea
@fwrite($handle, chr(10) . chr(10) . chr(10) . chr(10) . chr(10) . chr(29) . chr(86) . chr(49) . chr(12)); //cut papel
@fclose($handle); // cierra el fichero PRN*/