コード例 #1
5
<?php

require_once __DIR__ . "/../server/printer/Escpos.php";
/**
 * Created by PhpStorm.
 * User: jantonio
 * Date: 11/01/16
 * Time: 13:58
 */
/* bash$ sudo mkfifo -m 0666 /tmp/rawprint.fifo */
$connector = new FilePrintConnector(__DIR__ . "/../../logs/rawprint.fifo");
$printer = new Escpos($connector, SimpleCapabilityProfile::getInstance());
if (!$printer) {
    echo "Failed";
    return;
}
$data = json_encode(array("a" => "Hello", "b" => "World"));
$printer->initialize();
$printer->text($data . "\n");
$printer->cut();
$printer->close();
echo "Done";
コード例 #2
0
ファイル: usbText.php プロジェクト: GuoDapeng/escpos-php
 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;
     }
 }
コード例 #3
-1
<?php

/*
 * Example of printing Spanish text on SEYPOS PRP-300 thermal line printer.
 * The characters in Spanish are available in code page 437, so no special
 * code pages are needed in this case (SimpleCapabilityProfile).
 *
 * Use the hardware switch to activate "Two-byte Character Code"
 */
require_once dirname(__FILE__) . "/../../Escpos.php";
$connector = new FilePrintConnector("php://output");
$profile = SimpleCapabilityProfile::getInstance();
$printer = new Escpos($connector);
$printer->text("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n");
$printer->cut();
$printer->close();