foreach ($pages as $page) {
$printer->graphics($page, Printer::IMG_DOUBLE_HEIGHT | Printer::IMG_DOUBLE_WIDTH);
}
$printer->cut();
$printer->close();
/*
* 3: PDF printing still too slow? If you regularly print the same files, serialize & compress your
* EscposImage objects (after printing[1]), instead of throwing them away.
*
* (You can also do this to print logos on computers which don't have an
* image processing library, by preparing a serialized version of your logo on your PC)
*
* [1]After printing, the pixels are loaded and formatted for the print command you used, so even a raspberry pi can print complex PDF's quickly.
*/
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
$pdf = 'resources/document.pdf';
$ser = 'resources/document.z';
if (!file_exists($ser)) {
$pages = ImagickEscposImage::loadPdf($pdf);
} else {
$pages = unserialize(gzuncompress(file_get_contents($ser)));
}
foreach ($pages as $page) {
$printer->graphics($page);
}
$printer->cut();
$printer->close();
if (!file_exists($ser)) {
file_put_contents($ser, gzcompress(serialize($pages)));
}