Select justification.
public setJustification ( integer $justification = Printer::JUSTIFY_LEFT ) | ||
$justification | integer | One of Printer::JUSTIFY_LEFT, Printer::JUSTIFY_CENTER, or Printer::JUSTIFY_RIGHT. |
$printer -> setEmphasis(false); foreach(array(16, 32, 64, 128, 255) as $spacing) { $printer -> setLineSpacing($spacing); $printer -> text("Spacing $spacing: The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\n"); } $printer -> setLineSpacing(); // Back to default */ /* Stuff around with left margin */ $printer->setEmphasis(true); $printer->text("Left margin\n"); $printer->setEmphasis(false); $printer->text("Default left\n"); foreach (array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512) as $margin) { $printer->setPrintLeftMargin($margin); $printer->text("left margin {$margin}\n"); } /* Reset left */ $printer->setPrintLeftMargin(0); /* Stuff around with page width */ $printer->setEmphasis(true); $printer->text("Page width\n"); $printer->setEmphasis(false); $printer->setJustification(Printer::JUSTIFY_RIGHT); $printer->text("Default width\n"); foreach (array(512, 256, 128, 64) as $width) { $printer->setPrintWidth($width); $printer->text("page width {$width}\n"); } /* Printer shutdown */ $printer->cut(); $printer->close();
} $printer->setDoubleStrike(false); $printer->cut(); /* Fonts (many printers do not have a 'Font C') */ $fonts = array(Printer::FONT_A, Printer::FONT_B, Printer::FONT_C); for ($i = 0; $i < count($fonts); $i++) { $printer->setFont($fonts[$i]); $printer->text("The quick brown fox jumps over the lazy dog\n"); } $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);
<?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();