示例#1
3
<?php

/* Example print-outs using the older bit image print command */
require_once dirname(__FILE__) . "/../Escpos.php";
$printer = new Escpos();
try {
    $tux = new EscposImage("resources/tux.png");
    $printer->text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n");
    $printer->bitImage($tux);
    $printer->text("Regular Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Escpos::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Large Tux in correct proportion (bit image).\n");
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
    $printer->text($e->getMessage() . "\n");
}
$printer->cut();
$printer->close();
 /**
  * {@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;
 }
示例#3
2
    $source = "http://en.m.wikipedia.org/wiki/ESC/P";
    $width = 550;
    $dest = tempnam(sys_get_temp_dir(), 'escpos') . ".png";
    $cmd = sprintf("wkhtmltoimage -n -q --width %s %s %s", escapeshellarg($width), escapeshellarg($source), escapeshellarg($dest));
    /* Run wkhtmltoimage */
    ob_start();
    system($cmd);
    // Can also use popen() for better control of process
    $outp = ob_get_contents();
    ob_end_clean();
    if (!file_exists($dest)) {
        throw new Exception("Command {$cmd} failed: {$outp}");
    }
    /* Load up the image */
    try {
        $img = new EscposImage($dest);
    } catch (Exception $e) {
        unlink($dest);
        throw $e;
    }
    unlink($dest);
    /* Print it */
    $printer = new Escpos();
    // Add connector for your printer here.
    $printer->bitImage($img);
    // bitImage() seems to allow larger images than graphics() on the TM-T20.
    $printer->cut();
    $printer->close();
} catch (Exception $e) {
    echo $e->getMessage();
}
示例#4
0
function printer()
{
    // Create QR code in temp file, and print it.
    $tmpfname = tempnam(sys_get_temp_dir(), "escpos-php");
    $tmpfname .= ".png";
    $url = "http://www.baidu.com";
    QRcode::png($url, $tmpfname, 'L', 5, 0);
    $img = new EscposImage($tmpfname);
    // Load image
    //$connector = new NetworkPrintConnector("192.168.6.100", 9100);
    $connector = new FilePrintConnector("/dev/usb/lp0");
    // Add connector to your printer here
    $printer = new Escpos($connector);
    $printer->bitImage($img);
    $printer->text($url . "\n");
    $printer->feed();
    $printer->cut();
    $printer->close();
}
示例#5
0
    $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 */
    $printer->text($e->getMessage() . "\n");
}
$printer->cut();
/* QR Code - see also the more in-depth demo at qr-code.php */
$testStr = "Testing 123";
$models = array(Escpos::QR_MODEL_1 => "QR Model 1", Escpos::QR_MODEL_2 => "QR Model 2 (default)", Escpos::QR_MICRO => "Micro QR code\n(not supported on all printers)");
foreach ($models as $model => $name) {
    $printer->qrCode($testStr, Escpos::QR_ECLEVEL_L, 3, $model);
    $printer->text("{$name}\n");
    $printer->feed();
}
$printer->cut();
						</tr>
						
		<?php 
    }
    //send info to printer for printing vouchers.
    require_once dirname(__FILE__) . "/escpos/Escpos.php";
    $connector = null;
    $connector = new WindowsPrintConnector($printername);
    $printer = new Escpos($connector);
    /* Initialize Printer */
    $printer->initialize();
    $printer->setJustification(Escpos::JUSTIFY_CENTER);
    $printer->setTextSize(2, 2);
    $printer->text("WIFI HOTSPOT\n");
    $logo = new EscposImage("escpos/escposlogo.png");
    $printer->bitImage($logo);
    $printer->setTextSize(1, 1);
    $printer->text("\nNOTE: Each code valid for one\n");
    $printer->text("device only.\n\n");
    $printer->text("Download Speed " . $downloadspeed . " kbps\n");
    $printer->text("Upload Speed " . $uploadspeed . " kbps\n");
    $printer->text("Quota " . $quota . " MB\n");
    $printer->text("\n");
    $printer->setTextSize(2, 2);
    $printer->text($voucherstring . "\n");
    $printer->text("Usable One Time\n\n");
    $printer->setTextSize(1, 2);
    $printer->text("Valid For " . $_POST['length'] . " " . $unitlength . " From Login\n\n");
    $printer->setTextSize(1, 1);
    $printer->text("Connect to Hotspot\n");
    $printer->text("'" . $ssid . "'\n");
示例#7
0
 public static function pwresetReceipt(AccountOwner_model $owner, $password)
 {
     if (!isset(self::$conf['ip']) || self::$conf['ip'] == "0.0.0.0") {
         return false;
     }
     try {
         $connector = new NetworkPrintConnector(self::$conf['ip'], self::$conf['port']);
         $profile = SimpleCapabilityProfile::getInstance();
         $printer = new Escpos($connector, $profile);
         /* Header */
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         if (isset(self::$conf['logo']) && file_exists(self::$conf['logo'])) {
             try {
                 /* Include top image if set & available */
                 $logofile = self::$conf['logo'];
                 $ser = $logofile . ".ser";
                 if (file_exists($ser)) {
                     $img = unserialize(file_get_contents($ser));
                 } else {
                     $img = new EscposImage($logofile);
                     @file_put_contents($ser, serialize($img));
                     // Attempt to cache
                 }
                 $printer->bitImage($img);
             } catch (Exception $e) {
                 trigger_error($e->getMessage());
             }
         }
         $printer->setEmphasis(true);
         $printer->text(self::$conf['header'] . "\n");
         $printer->setEmphasis(false);
         $printer->feed();
         $printer->text("User Account Information\n");
         $printer->feed(2);
         $printer->setJustification(Escpos::JUSTIFY_LEFT);
         /* User info */
         $barcode = "";
         $seen = array();
         $printer->text("User Account:\n  " . $owner->owner_firstname . " " . $owner->owner_surname . "\n\n");
         $printer->text("Login name(s):\n");
         foreach ($owner->list_Account as $acct) {
             if (!isset($seen[$acct->account_login])) {
                 $printer->text("  " . $acct->account_login . "\n");
                 $seen[$acct->account_login] = true;
                 if (is_numeric($acct->account_login) && ($barcode == "" || strlen($acct->account_login) < strlen($barcode))) {
                     $barcode = $acct->account_login;
                 }
             }
         }
         $printer->feed();
         $printer->text("Password:\n  {$password}\n");
         $printer->feed(2);
         /* Footer */
         $printer->text(self::$conf['footer'] . "\n");
         $printer->feed();
         /* Barcode */
         if ($barcode != "") {
             $printer->setJustification(Escpos::JUSTIFY_CENTER);
             $printer->barcode($barcode, Escpos::BARCODE_CODE39);
             $printer->feed();
             $printer->text($barcode);
             $printer->feed(1);
             $printer->setJustification(Escpos::JUSTIFY_LEFT);
         }
         $printer->cut();
         $printer->close();
     } catch (Exception $e) {
         trigger_error($e->getMessage());
         // Should be logged some-place for troubleshooting.
         return false;
     }
 }