示例#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
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;
 }
 * The use case here is an Epson TM-T20II and German text.
 * 
 * Background: Not all ESC/POS features are available in the driver, so sometimes
 * you might want to send a custom commnad. This is useful for testing
 * new features.
 * 
 * The Escpos::text() function removes non-printable characters as a precaution,
 * so that commands cannot be injected into user input. To send raw data to
 * the printer, you need to write bytes to the underlying PrintConnector.
 * 
 * If you get a new command working, please file an issue on GitHub with a code
 * snippet so that it can be incorporated into escpos-php.
 */
/* Set up profile & connector */
$connector = new FilePrintConnector("php://output");
$profile = DefaultCapabilityProfile::getInstance();
// Works for Epson printers
$printer = new Escpos($connector, $profile);
$cmd = Escpos::ESC . "V" . chr(1);
// Try out 90-degree rotation.
$printer->getPrintConnector()->write($cmd);
$printer->text("Beispieltext in Deutsch\n");
$printer->cut();
$printer->close();
/*
 * Hex-dump of output confirms that ESC V 1 being sent:
 *
 * 0000000 033   @ 033   V 001   B   e   i   s   p   i   e   l   t   e   x
 * 0000010   t       i   n       D   e   u   t   s   c   h  \n 035   V   A
 * 0000020 003
 */
示例#5
2
<?php

/* Change to the correct path if you copy this example! */
require_once dirname(__FILE__) . "/../../Escpos.php";
/* Most printers are open on port 9100, so you just need to know the IP 
 * address of your receipt printer, and then fsockopen() it on that port.
 */
try {
    $connector = null;
    //$connector = new NetworkPrintConnector("10.x.x.x", 9100);
    /* Print a "Hello world" receipt" */
    $printer = new Escpos($connector);
    $printer->text("Hello World!\n");
    $printer->cut();
    /* Close printer */
    $printer->close();
} catch (Exception $e) {
    echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
}
示例#6
1
<?php

/* Print-outs using the newer graphics print command */
require_once dirname(__FILE__) . "/../Escpos.php";
$printer = new Escpos();
try {
    $tux = new EscposImage("resources/tux.png");
    $printer->graphics($tux);
    $printer->text("Regular Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Escpos::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Large Tux in correct proportion.\n");
    $printer->cut();
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
    $printer->text($e->getMessage() . "\n");
}
$printer->close();
示例#7
0
function title(Escpos $printer, $text)
{
    $printer->selectPrintMode(Escpos::MODE_EMPHASIZED);
    $printer->text("\n" . $text);
    $printer->selectPrintMode();
    // Reset
}
示例#8
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();
}
        ?>
 MB</td>
						</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);
示例#10
0
$items = array(new item("Example item #1", "4.00"), new item("Another thing", "3.50"), new item("Something else", "1.00"), new item("A final item", "4.45"));
$subtotal = new item('Subtotal', '12.95');
$tax = new item('A local tax', '1.30');
$total = new item('Total', '14.25', true);
/* Date is kept the same for testing */
// $date = date('l jS \of F Y h:i:s A');
$date = "Monday 6th of April 2015 02:56:25 PM";
/* Start the printer */
//$logo = new EscposImage("resources/escpos-php.png");
$printer = new Escpos();
/* Print top logo */
$printer->setJustification(Escpos::JUSTIFY_CENTER);
//$printer -> graphics($logo);
/* Name of shop */
$printer->selectPrintMode(Escpos::MODE_DOUBLE_WIDTH);
$printer->text("ExampleMart Ltd.\n");
$printer->selectPrintMode();
$printer->text("Shop No. 42.\n");
$printer->feed();
/* Title of receipt */
$printer->setEmphasis(true);
$printer->text("SALES INVOICE\n");
$printer->setEmphasis(false);
/* Items */
$printer->setJustification(Escpos::JUSTIFY_LEFT);
$printer->setEmphasis(true);
$printer->text(new item('', '$'));
$printer->setEmphasis(false);
foreach ($items as $item) {
    $printer->text($item);
}
 * times in the example, and b) It involves sending very wide images, which printers don't like!
 * 
 * There are currently no test cases around the image printing, since it is an experimental feature.
 *
 * It does, however, illustrate the way that more encodings are available when image output is used.
 */
include dirname(__FILE__) . '/resources/character-encoding-test-strings.inc';
try {
    // Enter connector and capability profile
    $connector = new FilePrintConnector("php://stdout");
    $profile = DefaultCapabilityProfile::getInstance();
    $buffers = array(new EscposPrintBuffer(), new ImagePrintBuffer());
    /* Print a series of receipts containing i18n example strings */
    $printer = new Escpos($connector, $profile);
    $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
    $printer->text("Implemented languages\n");
    $printer->selectPrintMode();
    foreach ($inputsOk as $label => $str) {
        $printer->setEmphasis(true);
        $printer->text($label . ":\n");
        $printer->setEmphasis(false);
        foreach ($buffers as $buffer) {
            $printer->setPrintBuffer($buffer);
            $printer->text($str);
        }
        $printer->setPrintBuffer($buffers[0]);
    }
    $printer->feed();
    $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
    $printer->text("Works in progress\n");
    $printer->selectPrintMode();
示例#12
0
 function outprint($receipt, $pname, $noplate, $containerno, $invoiceno, $intime, $outtime, $hours, $charges)
 {
     require_once "assets/escpos-php/Escpos.php";
     try {
         // Enter the share name for your USB printer here
         $connector = new WindowsPrintConnector("epson");
         $printer = new Escpos($connector);
         /* Print top logo */
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         /* Name of shop */
         $printer->selectPrintMode(Escpos::MODE_DOUBLE_WIDTH);
         $printer->text("BILL/OUTPASS \n");
         $printer->text("\nNhavaSheva toll plaza\n");
         $printer->text("Operated By\n");
         $printer->text("Shree Sai Samartha\n");
         $printer->text("Enterprises Pay & Park\n");
         $printer->selectPrintMode();
         $printer->feed();
         /* Title of receipt */
         /* Items */
         $printer->setJustification(Escpos::JUSTIFY_LEFT);
         $printer->setEmphasis(true);
         $printer->setTextSize(2, 1);
         $printer->text("RECEIPT NO :" . $receipt . "\n");
         $printer->feed();
         $printer->setTextSize(2, 1);
         $printer->text("V. TYPE    :" . $pname . "\n");
         $printer->setTextSize(2, 2);
         $printer->text("V.NO       :" . $noplate . "\n");
         $printer->feed();
         $printer->setTextSize(2, 1);
         /*$printer -> text("IN DT:".date('d/m/y',strtotime($intime))."TM:".date('h:i:s',strtotime($intime))."\n");*/
         $printer->text("IN  :" . date('Y-m-d', strtotime($intime)) . " " . date('h:i:s', strtotime($intime)) . "\n");
         $printer->text("OUT :" . date('Y-m-d', strtotime($outtime)) . " " . date('h:i:s', strtotime($outtime)) . "\n");
         $printer->feed();
         $printer->text("DURATION : " . $hours . "\n");
         $printer->setTextSize(2, 2);
         $printer->feed();
         $printer->text("AMOUNT   : " . $charges);
         $printer->setTextSize(1, 1);
         $printer->setEmphasis(false);
         $printer->setEmphasis(true);
         $printer->setEmphasis(false);
         $printer->feed();
         /* Tax and total */
         /* Footer */
         $printer->feed(1);
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         $printer->text("THANK YOU! VISIT AGAIN!\n");
         //$printer -> feed(1);
         //$printer -> text(date('l jS \of F Y h:i:s A') . "\n");
         /* Cut the receipt and open the cash drawer */
         $printer->cut();
         $printer->pulse();
         $printer->close();
     } catch (Exception $e) {
         echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
     }
     /* A wrapper to do organise item names & prices into columns */
     /* Close printer */
 }
示例#13
0
文件: Hello.php 项目: Giovasdf/escphp
<html>
<body>

	Welcome <?php 
echo $_POST["rut"];
?>
<br>
<?php 
$rut1 = $_POST["rut"];
require_once dirname(__FILE__) . "/Escpos.php";
try {
    $connector = new WindowsPrintConnector("POS80");
    $printer = new Escpos($connector);
    $printer->text($rut1);
    /* Close printer */
    $printer->close();
} catch (Exception $e) {
    echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
}
?>
</body>
</html>
 page, you can set up a CapabilityProfile which either references its
 iconv encoding name, or includes all of the available characters.

 Here, we make use of CP858 for its inclusion of currency symbols which
 are not available in CP437. CP858 has good printer support, but is not
 included in all iconv builds.
*/
class CustomCapabilityProfile extends SimpleCapabilityProfile
{
    function getCustomCodePages()
    {
        /*
         * Example to print in a specific, user-defined character set
         * on a printer which has been configured to use i
         */
        return array('CP858' => "ÇüéâäàåçêëèïîìÄÅ" . "ÉæÆôöòûùÿÖÜø£Ø׃" . "áíóúñѪº¿®¬½¼¡«»" . "░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐" . "└┴┬├─┼ãÃ╚╔╩╦╠═╬¤" . "ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀" . "ÓßÔÒõÕµþÞÚÛÙýݯ´" . " ±‗¾¶§÷¸°¨·¹³²■ ");
    }
    function getSupportedCodePages()
    {
        return array(0 => 'custom:CP858');
    }
}
$connector = new FilePrintConnector("php://stdout");
$profile = CustomCapabilityProfile::getInstance();
$printer = new Escpos($connector, $profile);
$printer->text("€ 9,95\n");
$printer->text("£ 9.95\n");
$printer->text("\$ 9.95\n");
$printer->text("¥ 9.95\n");
$printer->cut();
$printer->close();
 function print_receipt($id)
 {
     $struk = $this->menu_model->getStruks(array('where' => array('pembayaran.id_order' => $id)));
     $conf = $this->office_model->get_config_resto();
     require_once dirname(__FILE__) . "/Escpos.php";
     $fp = fopen("/dev/usb/lp1", "w");
     $printer = new Escpos($fp);
     $printer->lineSpacing(19);
     $printer->setJustification(1);
     $printer->text($conf->row('nama_resto') . "\n");
     $printer->text($conf->row('alamat_resto') . "\n");
     $printer->text($conf->row('telephone') . $hp . "\n");
     $printer->setJustification();
     $printer->text("\n");
     $printer->text("No. Meja : " . $struk->row('no_meja') . " || Nama : " . $struk->row('nama_konsumen') . "\n");
     $printer->text("----------------------------------------");
     $printer->text("Nama Menu          Jml  Harga   SubTot\n");
     $printer->text("----------------------------------------");
     foreach ($struk->result() as $key => $v) {
         $sub_tot = $v->harga * $v->jumlah_selesai;
         $printer->text($v->nama_menu . " \n");
         $printer->setJustification(2);
         $printer->text($v->jumlah_selesai . " | " . outNominal($v->harga) . " | " . outNominal($sub_tot) . " \n");
         $printer->setJustification();
     }
     $printer->text("         -------------------------------");
     $printer->text("                 TOTAL  : Rp.   " . outNominal($struk->row('total')) . " \n");
     $printer->text("                 DISC   : %     " . $struk->row('discount') . " \n");
     $printer->text("           GRAND TOTAL  : Rp.   " . outNominal($struk->row('grand_total')) . " \n");
     $printer->text("                 TUNAI  : Rp.   " . outNominal($struk->row('fisik_uang')) . " \n");
     $printer->text("                 KEMBALI: Rp.   " . outNominal($struk->row('kembali')) . " \n");
     $printer->text("----------------------------------------");
     $printer->setJustification(1);
     $printer->text("Terimakasih atas kunjunganya.\n");
     $printer->setJustification();
     $printer->text("----------------------------------------");
     $printer->text("Kasir : " . $this->session->userdata('display_name') . "       \n");
     $printer->text(date("d/m/Y H:i:s") . "\n");
     $printer->text("\n");
     $printer->text("\n");
     $printer->cut();
 }
示例#16
0
<?php

/*
 * Example of two-color printing, tested on an epson TM-U220 with two-color ribbon installed.
 */
require_once dirname(__FILE__) . "/../../Escpos.php";
$connector = new FilePrintConnector("/dev/usb/lp0");
try {
    $printer = new Escpos($connector);
    $printer->text("Hello World!\n");
    $printer->setColor(Escpos::COLOR_2);
    $printer->text("Red?!\n");
    $printer->setColor(Escpos::COLOR_1);
    $printer->text("Default color again?!\n");
    $printer->cut();
} finally {
    /* Always close the printer! */
    $printer->close();
}
示例#17
0
<?php

require_once dirname(__FILE__) . "/../Escpos.php";
$printer = new Escpos();
$printer->setBarcodeHeight(40);
/* Text position */
$printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH);
$printer->text("Text position\n");
$printer->selectPrintMode();
$hri = array(Escpos::BARCODE_TEXT_NONE => "No text", Escpos::BARCODE_TEXT_ABOVE => "Above", Escpos::BARCODE_TEXT_BELOW => "Below", Escpos::BARCODE_TEXT_ABOVE | Escpos::BARCODE_TEXT_BELOW => "Both");
foreach ($hri as $position => $caption) {
    $printer->text($caption . "\n");
    $printer->setBarcodeTextPosition($position);
    $printer->barcode("012345678901", Escpos::BARCODE_JAN13);
    $printer->feed();
}
/* Barcode types */
$standards = array(Escpos::BARCODE_UPCA => array("title" => "UPC-A", "caption" => "Fixed-length numeric product barcodes.", "example" => array(array("caption" => "12 char numeric including (wrong) check digit.", "content" => "012345678901"), array("caption" => "Send 11 chars to add check digit automatically.", "content" => "01234567890"))), Escpos::BARCODE_UPCE => array("title" => "UPC-E", "caption" => "Fixed-length numeric compact product barcodes.", "example" => array(array("caption" => "6 char numeric - auto check digit & NSC", "content" => "123456"), array("caption" => "7 char numeric - auto check digit", "content" => "0123456"), array("caption" => "8 char numeric", "content" => "01234567"), array("caption" => "11 char numeric - auto check digit", "content" => "01234567890"), array("caption" => "12 char numeric including (wrong) check digit", "content" => "012345678901"))), Escpos::BARCODE_JAN13 => array("title" => "JAN13/EAN13", "caption" => "Fixed-length numeric barcodes.", "example" => array(array("caption" => "12 char numeric - auto check digit", "content" => "012345678901"), array("caption" => "13 char numeric including (wrong) check digit", "content" => "0123456789012"))), Escpos::BARCODE_JAN8 => array("title" => "JAN8/EAN8", "caption" => "Fixed-length numeric barcodes.", "example" => array(array("caption" => "7 char numeric - auto check digit", "content" => "0123456"), array("caption" => "8 char numeric including (wrong) check digit", "content" => "01234567"))), Escpos::BARCODE_CODE39 => array("title" => "Code39", "caption" => "Variable length alphanumeric w/ some special chars.", "example" => array(array("caption" => "Text, numbers, spaces", "content" => "ABC 012"), array("caption" => "Special characters", "content" => "\$%+-./"), array("caption" => "Extra char (*) Used as start/stop", "content" => "*TEXT*"))), Escpos::BARCODE_ITF => array("title" => "ITF", "caption" => "Variable length numeric w/even number of digits,\nas they are encoded in pairs.", "example" => array(array("caption" => "Numeric- even number of digits", "content" => "0123456789"))), Escpos::BARCODE_CODABAR => array("title" => "Codabar", "caption" => "Varaible length numeric with some allowable\nextra characters. ABCD/abcd must be used as\nstart/stop characters (one at the start, one\nat the end) to distinguish between barcode\napplications.", "example" => array(array("caption" => "Numeric w/ A A start/stop. ", "content" => "A012345A"), array("caption" => "Extra allowable characters", "content" => "A012\$+-./:A"))), Escpos::BARCODE_CODE93 => array("title" => "Code93", "caption" => "Variable length- any ASCII is available", "example" => array(array("caption" => "Text", "content" => "012abcd"))), Escpos::BARCODE_CODE128 => array("title" => "Code128", "caption" => "Variable length- any ASCII is available", "example" => array(array("caption" => "Code set A uppercase & symbols", "content" => "{A" . "012ABCD"), array("caption" => "Code set B general text", "content" => "{B" . "012ABCDabcd"), array("caption" => "Code set C compact numbers\n Sending chr(21) chr(32) chr(43)", "content" => "{C" . chr(21) . chr(32) . chr(43)))));
$printer->setBarcodeTextPosition(Escpos::BARCODE_TEXT_BELOW);
foreach ($standards as $type => $standard) {
    $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH);
    $printer->text($standard["title"] . "\n");
    $printer->selectPrintMode();
    $printer->text($standard["caption"] . "\n\n");
    foreach ($standard["example"] as $id => $barcode) {
        $printer->setEmphasis(true);
        $printer->text($barcode["caption"] . "\n");
        $printer->setEmphasis(false);
        $printer->text("Content: " . $barcode["content"] . "\n");
        $printer->barcode($barcode["content"], $type);
        $printer->feed();
示例#18
0
<?php

require_once dirname(__FILE__) . "/escpos-php-master/Escpos.php";
//$logo = new EscposImage("images/productos/tostao.jpg");
$printer = new Escpos();
/* Print top logo */
$printer->setJustification(Escpos::JUSTIFY_CENTER);
$printer->setEmphasis(true);
$printer->text("FACTURA \n");
$printer->text("Computel Peru S.A.C. \n");
$printer->text("Csan Jose N° 1122 Chiclayo-Lambayeque \n");
$printer->text("ruc: \n");
$printer->text("TICKET \n");
$printer->text("001-000040\n");
$printer->setEmphasis(false);
$printer->feed();
$printer->setJustification();
$printer->setFont(Escpos::FONT_C);
$printer->feed();
$printer->text("#CAJA:16       20-02-2016 11:12:01\n");
$printer->text("Ticket                  <original>\n");
$printer->text("-------------------------------------\n");
$printer->text("TIPO:Efec. DNI N°:\n");
$printer->text("Cliente: BARTOLOME CURO\n");
$printer->feed();
$printer->text("Direccion: \n");
$printer->feed();
$printer->text("Cajero: admin\n");
$printer->text("Vendedor: .....\n");
$printer->text("-------------------------------------\n");
$printer->text("Descripcion \n");
示例#19
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;
     }
 }
示例#20
0
/**
 * Created by IntelliJ IDEA.
 * User: GuoDapeng
 * Date: 15/10/12
 * Time: 下午4:31
 */
require_once dirname(__FILE__) . "/../libs/phpqrcode/qrlib.php";
require_once dirname(__FILE__) . "/../Escpos.php";
// 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
try {
    //    $connector = new NetworkPrintConnector("192.168.6.200", 9100);
    //$connector = new NetworkPrintConnector("192.168.6.100", 9100);
    //$connector = new NetworkPrintConnector("localhost", 1337);
    $connector = new NetworkPrintConnector("localhost", 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();
} catch (Exception $e) {
    print_r($e);
}
示例#21
0
function title(Escpos $printer, $str)
{
    $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH);
    $printer->text($str);
    $printer->selectPrintMode();
}
示例#22
0
/**
 * 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;
    for ($j = 0; $j < strlen($bits); $j++) {
<?php

require_once dirname(__FILE__) . "/../../Escpos.php";
/* This example shows the printing of Latvian text on the Star TUP 592 printer */
$profile = StarCapabilityProfile::getInstance();
/* Option 1: Native character encoding */
$connector = new FilePrintConnector("php://stdout");
$printer = new Escpos($connector, $profile);
$printer->text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
$printer->cut();
$printer->close();
/* Option 2: Image-based output (formatting not available using this output) */
$buffer = new ImagePrintBuffer();
$connector = new FilePrintConnector("php://stdout");
$printer = new Escpos($connector, $profile);
$printer->setPrintBuffer($buffer);
$printer->text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
$printer->cut();
$printer->close();
示例#24
-1
 function vehicle_print($data)
 {
     require_once "assets/escpos-php/Escpos.php";
     try {
         // Enter the share name for your USB printer here
         $connector = new WindowsPrintConnector("epson");
         $printer = new Escpos($connector);
         $age = array("Monday" => "35", "Tuesday" => "37", "Wednesday" => "43");
         $day = jddayofweek(cal_to_jd(CAL_GREGORIAN, date("m"), date("d"), date("Y")), 1);
         /* Print top logo */
         /*print report start*/
         $exceldata = "";
         $t_charges = 0;
         $total_hours = 0;
         foreach ($data->result_array() as $row) {
             $pid = $row['pid'];
             $vtype = $row['name'];
             $noplate = $row['noplate'];
             $intime = $row['intime'];
             if ($row['status'] == 0) {
                 $status = 'IN';
             }
             if ($row['status'] == 1) {
                 $status = 'OUT';
             }
             if (isset($row['outtime'])) {
                 $outtime = $row['outtime'];
                 $new_hours = $row['hours'];
                 $total_charges = $row['charges'];
             } else {
                 $in = $row['intime'];
                 $out = date('Y-m-d H:i:s', time());
                 $hour1 = 0;
                 $hour2 = 0;
                 $date1 = $in;
                 $date2 = $out;
                 $datetimeObj1 = new DateTime($date1);
                 $datetimeObj2 = new DateTime($date2);
                 $interval = $datetimeObj1->diff($datetimeObj2);
                 if ($interval->format('%a') > 0) {
                     $hour1 = $interval->format('%a') * 24;
                 }
                 if ($interval->format('%h') > 0) {
                     $hour2 = $interval->format('%h');
                 }
                 $hrs = $hour1 + $hour2;
                 $hrs = sprintf("%02d", $hrs);
                 $minutes = $interval->format('%i');
                 $minutes = sprintf("%02d", $minutes);
                 $secs = $interval->format('%s');
                 $secs = sprintf("%02d", $secs);
                 $new_hours = $hrs . ":" . $minutes . ":" . $secs;
                 $sql = "select charges from charges where typeid = (select id from parktype where name = '{$vtype}' )";
                 $query = $this->db->query($sql);
                 $result = $query->result();
                 $result1 = array();
                 foreach ($result as $key => $value) {
                     $result1['charges'] = $value->charges;
                 }
                 $charges = $result1['charges'];
                 $tot_str = $hrs . '.' . $minutes;
                 $hour_in_float = (double) $tot_str;
                 $total_charges = ceil($hour_in_float / 8) * $charges;
             }
             $to_seconds = $this->time_to_seconds($new_hours);
             /*******total hours calculation*****/
             $total_hours = $total_hours + $to_seconds;
             $hours = floor($total_hours / (60 * 60));
             $divisor_for_minutes = $total_hours % (60 * 60);
             $minutes = floor($divisor_for_minutes / 60);
             // extract the remaining seconds
             $divisor_for_seconds = $divisor_for_minutes % 60;
             $seconds = ceil($divisor_for_seconds);
             $t_hours_sec = (int) $hours . ':' . (int) $minutes . ':' . (int) $seconds;
             /***********average hours calculation*********/
             $ave_hours = $total_hours / count($data->result_array());
             $hours = floor($ave_hours / (60 * 60));
             $divisor_for_minutes = $ave_hours % (60 * 60);
             $minutes = floor($divisor_for_minutes / 60);
             $divisor_for_seconds = $divisor_for_minutes % 60;
             $seconds = ceil($divisor_for_seconds);
             $ave_sec = (int) $hours . ':' . (int) $minutes . ':' . (int) $seconds;
             /*****************/
             $exceldata[] = array($pid, $vtype, $noplate, $intime, $row['outtime'], $new_hours, $total_charges, $status);
             $charges = $total_charges;
             $charges_t = $charges_t + $charges;
             $ii = 1;
             $objPHPExcel->getActiveSheet()->getStyle('A' . $ii . ':H' . $ii)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
             $ii++;
         }
         $exceldata[] = array('', 'TOTAl :' . count($data->result_array()), 'Total Hours :', $t_hours_sec, 'average hours :', $ave_sec, 'Total Charges  :', $charges_t);
         //$exceldata[] = array('','','','','','average hours :'.$ave_sec,'','');
         $excel_c = count($data->result_array()) + 4;
         /*for($col = ord('A'.$excel_c); $col <= ord('F'.$excel_c); $col++){
              $objPHPExcel->getActiveSheet()->getStyle(chr($col))->getFont()->setSize(14);
               $objPHPExcel->getActiveSheet()->getStyle(chr($col))->getFont()->setBold(true);
               $objPHPExcel->getActiveSheet()->getStyle(chr($col))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
           }*/
         //$objPHPExcel->getActiveSheet()->getColumnDimension('G'.$excel_c)->setWidth(20);
         $objPHPExcel->getActiveSheet()->getRowDimension($excel_c)->setRowHeight(20);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFill()->getStartColor()->setARGB('29bb04');
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFont()->setSize(14);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFont()->setBold(true);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
         //Fill data
         $objPHPExcel->getActiveSheet()->fromArray($exceldata, null, 'A4');
         /*print report end*/
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         /* Name of shop */
         $printer->selectPrintMode(Escpos::MODE_DOUBLE_WIDTH);
         $printer->text("RECEIPT\n");
         $printer->text("\nNhavaSheva toll plaza\n");
         $printer->text("Operated By\n");
         $printer->text("Shree Sai Samartha\n");
         $printer->text("Enterprises Pay & Park\n");
         $printer->selectPrintMode();
         $printer->feed();
         /* Title of receipt */
         /* Items */
         $printer->setJustification(Escpos::JUSTIFY_LEFT);
         $printer->setEmphasis(true);
         $printer->setTextSize(2, 1);
         $rr = "RECEIPT NO :" . $receipt . "\n";
         $printer->text($rr);
         //$printer -> feed();
         $printer->text("V. TYPE    :" . $parktype . "\n");
         $printer->feed();
         $printer->setTextSize(2, 2);
         $printer->text("V.NO       :" . $noplate . "\n");
         $printer->text("CO. NO     :" . $containerno . "\n");
         $printer->text("VO. NO     :" . $invoiceno . "\n");
         //$printer -> feed();
         //$printer -> setTextSize(2,1);
         $printer->text("IN  DT :" . date('d/m/Y', strtotime($intime)) . "\n");
         $printer->text("IN  TM :" . date('h:i:s', strtotime($intime)) . "\n");
         $printer->setTextSize(2, 2);
         $printer->setTextSize(1, 1);
         $printer->setEmphasis(false);
         $printer->feed();
         /* Tax and total */
         /* Footer */
         //$printer -> feed(1);
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         $printer->text("PARKING AT OWNERS RISK. MANAGEMENT IS NOT LIABLE\n");
         $printer->text("TO PAY ANY LOSS OR DAMAGE OF ANY VEHICLE OR\n");
         $printer->text("VALUABLE LEFT INSIDE IT\n");
         //$printer -> feed(1);
         //$printer -> text(date('l jS \of F Y h:i:s A') . "\n");
         /* Cut the receipt and open the cash drawer */
         $printer->cut();
         $printer->pulse();
         $printer->close();
     } catch (Exception $e) {
         echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
     }
     /* A wrapper to do organise item names & prices into columns */
     /* Close printer */
 }
示例#25
-1
<?php

/* Example of Greek text on the P-822D */
require_once dirname(__FILE__) . "/../../Escpos.php";
// Setup the printer
$connector = new FilePrintConnector("php://stdout");
$profile = P822DCapabilityProfile::getInstance();
$printer = new Escpos($connector, $profile);
// Print a Greek pangram
$text = "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία";
$printer->text($text . "\n");
$printer->cut();
// Close the connection
$printer->close();
<?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();