Ejemplo n.º 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)));
}
Ejemplo n.º 2
1
<?php

/* Print-outs using the newer graphics print command */
require_once dirname(__FILE__) . "/../Escpos.php";
$printer = new Escpos();
try {
    $tux = new EscposImage("resources/tux.png");
    $printer->graphics($tux);
    $printer->text("Regular Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Escpos::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Large Tux in correct proportion.\n");
    $printer->cut();
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
    $printer->text($e->getMessage() . "\n");
}
$printer->close();
Ejemplo n.º 3
0
}
$printer->setJustification();
// Reset
$printer->cut();
/* Barcodes - see barcode.php for more detail */
$printer->setBarcodeHeight(80);
$printer->setBarcodeTextPosition(Escpos::BARCODE_TEXT_BELOW);
$printer->barcode("9876");
$printer->feed();
$printer->cut();
/* Graphics - this demo will not work on some non-Epson printers */
try {
    $logo = new EscposImage("resources/escpos-php.png");
    $imgModes = array(Escpos::IMG_DEFAULT, Escpos::IMG_DOUBLE_WIDTH, Escpos::IMG_DOUBLE_HEIGHT, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
    foreach ($imgModes as $mode) {
        $printer->graphics($logo, $mode);
    }
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
    $printer->text($e->getMessage() . "\n");
}
$printer->cut();
/* Bit image */
try {
    $logo = new EscposImage("resources/escpos-php.png");
    $imgModes = array(Escpos::IMG_DEFAULT, Escpos::IMG_DOUBLE_WIDTH, Escpos::IMG_DOUBLE_HEIGHT, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
    foreach ($imgModes as $mode) {
        $printer->bitImage($logo, $mode);
    }
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
Ejemplo n.º 4
0
$imgCombined_path = $tmpf_path . ".png";
try {
    // Convert, load image, remove temp files
    $cmd = sprintf("convert %s %s +append %s", escapeshellarg($img1_path), escapeshellarg($img2_path), escapeshellarg($imgCombined_path));
    exec($cmd, $outp, $retval);
    if ($retval != 0) {
        // Detect and handle command failure
        throw new Exception("Command \"{$cmd}\" returned {$retval}." . implode("\n", $outp));
    }
    $img = new EscposImage($imgCombined_path);
    // Setup the printer
    $connector = new FilePrintConnector("php://stdout");
    $profile = DefaultCapabilityProfile::getInstance();
    // Run the actual print
    $printer = new Escpos($connector, $profile);
    try {
        $printer->setJustification(Escpos::JUSTIFY_CENTER);
        $printer->graphics($img);
        $printer->cut();
    } finally {
        // Always close the connection
        $printer->close();
    }
} catch (Exception $e) {
    // Print out any errors: Eg. printer connection, image loading & external image manipulation.
    echo $e->getMessage() . "\n";
    echo $e->getTraceAsString();
} finally {
    unlink($imgCombined_path);
    unlink($tmpf_path);
}
Ejemplo n.º 5
0
require_once dirname(__FILE__) . "/../Escpos.php";
/* Information for the receipt */
$items = array(new item("Example item #1", "4.00"), new item("Another thing", "3.50"), new item("Something else", "1.00"), new item("A final item", "4.45"));
$subtotal = new item('Subtotal', '12.95');
$tax = new item('A local tax', '1.30');
$total = new item('Total', '14.25', true);
/* Date is kept the same for testing */
// $date = date('l jS \of F Y h:i:s A');
$date = "Monday 6th of April 2015 02:56:25 PM";
/* Start the printer */
$logo = new EscposImage("resources/escpos-php.png");
$printer = new Escpos();
/* Print top logo */
$printer->setJustification(Escpos::JUSTIFY_CENTER);
$printer->graphics($logo);
/* Name of shop */
$printer->selectPrintMode(Escpos::MODE_DOUBLE_WIDTH);
$printer->text("ExampleMart Ltd.\n");
$printer->selectPrintMode();
$printer->text("Shop No. 42.\n");
$printer->feed();
/* Title of receipt */
$printer->setEmphasis(true);
$printer->text("SALES INVOICE\n");
$printer->setEmphasis(false);
/* Items */
$printer->setJustification(Escpos::JUSTIFY_LEFT);
$printer->setEmphasis(true);
$printer->text(new item('', '$'));
$printer->setEmphasis(false);