We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

print a ticket

i need to directly send to the printer a ticket

can someone help me please

This isn't a Phalcon specific question. You will have better luck asking on a more general purpose forum like www.stackoverflow.com.

In my personal experience though, sending a print job to a printer from PHP is pretty much impossible.



8.1k

You can generate PDF or PostScript file and send it to printer (print-server). Usualy PDF file will generate and download to user on the site.



6.9k
Accepted
answer

this is actually pretty easy with message queing instead of using cron/scheduling

https://blog.jachim.be/2013/11/controlling-a-receipt-printer-with-zeromq-and-php/

<?php
/**
 * Receive a print request and print.
 */
$context = new ZMQContext();
$sub = $context->getSocket(ZMQ::SOCKET_SUB);
$sub->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, '');
$sub->connect('tcp://server:5566');

while (true) {
    $printJob = $sub->recv();

    $html = file_get_contents($printJob);
    $file = get_temp_dir() . '/printJob_' . sha1($html) . '.html';
    file_put_contents($file, $html);

    // https://windowsitpro.com/systems-management/how-can-i-print-usb-printer-command-prompt
    exec('print /d:LPT2: ' . $file);
}

whether or not its a good idea is something a lot of people have discussed