コード例 #1
1
$pages = EscposImage::loadPdf($pdf, 260);
foreach ($pages as $page) {
    $printer->graphics($page, Escpos::IMG_DOUBLE_HEIGHT | Escpos::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.
 */
$printer = new Escpos();
$pdf = 'resources/document.pdf';
$ser = 'resources/document.z';
if (!file_exists($ser)) {
    $pages = EscposImage::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)));
}