/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rootPath = $this->getContainer()->get('kernel')->getRootDir() . '/../';
     require_once $rootPath . 'vendor/mike42/escpos-php/Escpos.php';
     $imagePath = $rootPath . 'resources/elephant-256x256.png';
     $img = new \EscposImage($imagePath);
     $connector = new \FilePrintConnector('/dev/usb/lp0');
     $printer = new \Escpos($connector);
     $printer->initialize();
     $printer->text('*************************\\n');
     $printer->text('Un petit elephant');
     $printer->feed(2);
     $printer->bitImage($img);
     $printer->feed(2);
     $printer->text('*************************\\n');
     /* Always close the printer! On some PrintConnectors, no actual
      * data is sent until the printer is closed. */
     $printer->close();
     return 0;
 }
Beispiel #2
0
<?php

/**
 * This is a demo script for the functions of the PHP ESC/POS print driver,
 * Escpos.php.
 *
 * Most printers implement only a subset of the functionality of the driver, so
 * will not render this output correctly in all cases.
 *
 * @author Michael Billington <*****@*****.**>
 */
require_once dirname(__FILE__) . "/../Escpos.php";
$printer = new Escpos();
/* Initialize */
$printer->initialize();
/* Text */
$printer->text("Hello world\n");
$printer->cut();
/* Line feeds */
$printer->text("ABC");
$printer->feed(7);
$printer->text("DEF");
$printer->feedReverse(3);
$printer->text("GHI");
$printer->feed();
$printer->cut();
/* Font modes */
$modes = array(Escpos::MODE_FONT_B, Escpos::MODE_EMPHASIZED, Escpos::MODE_DOUBLE_HEIGHT, Escpos::MODE_DOUBLE_WIDTH, Escpos::MODE_UNDERLINE);
for ($i = 0; $i < pow(2, count($modes)); $i++) {
    $bits = str_pad(decbin($i), count($modes), "0", STR_PAD_LEFT);
    $mode = 0;