I have a script that creates a PDF document and proceed to send it to be printed. It happens that I need to wait for the document to be created, check that and recently sent for printing.
define('TIKET_DIR', public_path('temp/'));
$token = sha1(microtime().'tk');
$pdfPath = TIKET_DIR.$token.'.pdf';
$html2pdf = new HTML2PDF('V', array('72', '110'), 'es', true, 'UTF-8', 0);
$html2pdf->WriteHTML($html);
$html2pdf->Output($pdfPath, 'F');
$cmd = "lpr -P".$ococina->impresora." ";
$cmd .= $pdfPath;
$response = shell_exec($cmd);
The variable $html is dynamically created and may be delayed. Usually PDF document printed, but sometimes it does not print and I think this happens because the lpr command is executed without the PDF document is ready. I use LEMP on Ubuntu with CUPS print server. I have to turn off and turn on all printers connected to the computer and just the PDF document previously sent print.
Thanks in advance.