Print a barcode.
public barcode ( string $content, integer $type = Printer::BARCODE_CODE39 ) | ||
$content | string | The information to encode. |
$type | integer | The barcode standard to output. Supported values are `Printer::BARCODE_UPCA`, `Printer::BARCODE_UPCE`, `Printer::BARCODE_JAN13`, `Printer::BARCODE_JAN8`, `Printer::BARCODE_CODE39`, `Printer::BARCODE_ITF`, `Printer::BARCODE_CODABAR`, `Printer::BARCODE_CODE93`, and `Printer::BARCODE_CODE128`. If not specified, `Printer::BARCODE_CODE39` will be used. Note that some barcode formats only support specific lengths or sets of characters, and that available barcode types vary between printers. |
$printer->setFont(); // Reset $printer->cut(); /* Justification */ $justification = array(Printer::JUSTIFY_LEFT, Printer::JUSTIFY_CENTER, Printer::JUSTIFY_RIGHT); for ($i = 0; $i < count($justification); $i++) { $printer->setJustification($justification[$i]); $printer->text("A man a plan a canal panama\n"); } $printer->setJustification(); // Reset $printer->cut(); /* Barcodes - see barcode.php for more detail */ $printer->setBarcodeHeight(80); $printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW); $printer->barcode("9876"); $printer->feed(); $printer->cut(); /* Graphics - this demo will not work on some non-Epson printers */ try { $logo = EscposImage::load("resources/escpos-php.png", false); $imgModes = array(Printer::IMG_DEFAULT, Printer::IMG_DOUBLE_WIDTH, Printer::IMG_DOUBLE_HEIGHT, Printer::IMG_DOUBLE_WIDTH | Printer::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 */
<?php require __DIR__ . '/../autoload.php'; use Mike42\Escpos\Printer; use Mike42\Escpos\PrintConnectors\FilePrintConnector; $connector = new FilePrintConnector("php://stdout"); $printer = new Printer($connector); /* Height and width */ $printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH); $printer->text("Height and bar width\n"); $printer->selectPrintMode(); $heights = array(1, 2, 4, 8, 16, 32); $widths = array(1, 2, 3, 4, 5, 6, 7, 8); $printer->text("Default look\n"); $printer->barcode("ABC", Printer::BARCODE_CODE39); foreach ($heights as $height) { $printer->text("\nHeight {$height}\n"); $printer->setBarcodeHeight($height); $printer->barcode("ABC", Printer::BARCODE_CODE39); } foreach ($widths as $width) { $printer->text("\nWidth {$width}\n"); $printer->setBarcodeWidth($width); $printer->barcode("ABC", Printer::BARCODE_CODE39); } $printer->feed(); // Set to something sensible for the rest of the examples $printer->setBarcodeHeight(40); $printer->setBarcodeWidth(2); /* Text position */ $printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
<?php require __DIR__ . '/../../autoload.php'; use Mike42\Escpos\Printer; use Mike42\Escpos\PrintConnectors\FilePrintConnector; $a = "{A012323392982"; $b = "{B012323392982"; $c = "{C" . chr(01) . chr(23) . chr(23) . chr(39) . chr(29) . chr(82); $connector = new FilePrintConnector("php://stdout"); $printer = new Printer($connector); $printer->setJustification(Printer::JUSTIFY_CENTER); $printer->setBarcodeHeight(48); $printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW); foreach (array($a, $b, $c) as $item) { $printer->barcode($item, Printer::BARCODE_CODE128); $printer->feed(1); } $printer->cut(); $printer->close();