Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



7.0k

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.3k
Accepted
answer

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

http://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);

    // http://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