コード例 #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
ファイル: bit-image.php プロジェクト: ahmadshah/escpos-php
<?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();
コード例 #3
2
 /**
  * {@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;
 }
コード例 #4
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();
}
コード例 #5
2
 * 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
 */
コード例 #6
2
ファイル: ethernet.php プロジェクト: ahmadshah/escpos-php
<?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";
}
コード例 #7
1
ファイル: graphics.php プロジェクト: ahmadshah/escpos-php
<?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();
コード例 #8
1
$pages = EscposImage::loadPdf($pdf, 260);
foreach ($pages as $page) {
    $printer->graphics($page, Escpos::IMG_DOUBLE_HEIGHT | Escpos::IMG_DOUBLE_WIDTH);
}
$printer->cut();
$printer->close();
/*
 * 3: PDF printing still too slow? If you regularly print the same files, serialize & compress your
 * EscposImage objects (after printing[1]), instead of throwing them away.
 * 
 * (You can also do this to print logos on computers which don't have an
 * image processing library, by preparing a serialized version of your logo on your PC)
 * 
 * [1]After printing, the pixels are loaded and formatted for the print command you used, so even a raspberry pi can print complex PDF's quickly.
 */
$printer = new Escpos();
$pdf = 'resources/document.pdf';
$ser = 'resources/document.z';
if (!file_exists($ser)) {
    $pages = EscposImage::loadPdf($pdf);
} else {
    $pages = unserialize(gzuncompress(file_get_contents($ser)));
}
foreach ($pages as $page) {
    $printer->graphics($page);
}
$printer->cut();
$printer->close();
if (!file_exists($ser)) {
    file_put_contents($ser, gzcompress(serialize($pages)));
}
コード例 #9
0
ファイル: text-size.php プロジェクト: ahmadshah/escpos-php
function title(Escpos $printer, $text)
{
    $printer->selectPrintMode(Escpos::MODE_EMPHASIZED);
    $printer->text("\n" . $text);
    $printer->selectPrintMode();
    // Reset
}
コード例 #10
0
ファイル: server.php プロジェクト: GuoDapeng/escpos-php
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();
}
コード例 #11
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();
コード例 #12
0
 * This example builds on character-encodings.php, also providing an image-based rendering.
 * This is quite slow, since a) the buffers are changed dozens of
 * 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);
コード例 #13
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;
     }
 }
コード例 #14
0
ファイル: 68-redblack.php プロジェクト: Helw/escpos-php
<?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();
}
コード例 #15
0
$tmpf_path = tempnam(sys_get_temp_dir(), 'escpos-php');
$imgCombined_path = $tmpf_path . ".png";
try {
    // Convert, load image, remove temp files
    $cmd = sprintf("convert %s %s +append %s", escapeshellarg($img1_path), escapeshellarg($img2_path), escapeshellarg($imgCombined_path));
    exec($cmd, $outp, $retval);
    if ($retval != 0) {
        // Detect and handle command failure
        throw new Exception("Command \"{$cmd}\" returned {$retval}." . implode("\n", $outp));
    }
    $img = new EscposImage($imgCombined_path);
    // Setup the printer
    $connector = new FilePrintConnector("php://stdout");
    $profile = DefaultCapabilityProfile::getInstance();
    // Run the actual print
    $printer = new Escpos($connector, $profile);
    try {
        $printer->setJustification(Escpos::JUSTIFY_CENTER);
        $printer->graphics($img);
        $printer->cut();
    } finally {
        // Always close the connection
        $printer->close();
    }
} catch (Exception $e) {
    // Print out any errors: Eg. printer connection, image loading & external image manipulation.
    echo $e->getMessage() . "\n";
    echo $e->getTraceAsString();
} finally {
    unlink($imgCombined_path);
    unlink($tmpf_path);
コード例 #16
0
 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();
コード例 #17
0
 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();
 }
コード例 #18
0
<?php

require_once dirname(__FILE__) . "/../Escpos.php";
/* Information for the receipt */
$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('', '$'));
コード例 #19
0
        echo $uploadspeed;
        ?>
 kbps</td>
				      <td align="center" style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif;"><?php 
        echo $quota;
        ?>
 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);
コード例 #20
0
<?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();
コード例 #21
0
function title(Escpos $printer, $str)
{
    $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH);
    $printer->text($str);
    $printer->selectPrintMode();
}
コード例 #22
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>
コード例 #23
0
ファイル: demo.php プロジェクト: ahmadshah/escpos-php
<?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;
コード例 #24
0
ファイル: account.php プロジェクト: msd1310/ci_bootstrap
 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 */
 }
コード例 #25
0
 * numbers to iconv encoding names on your particular printer. This script
 * will print all configured code pages, so that you can check that the chosen
 * iconv encoding name matches the actual code page contents.
 * 
 * If this is correctly set up for your printer, then the driver will try its
 * best to map UTF-8 text into these code pages for you, allowing you to accept
 * arbitrary input from a database, without worrying about encoding it for the printer.
 */
require_once dirname(__FILE__) . "/../Escpos.php";
// Enter connector and capability profile (to match your printer)
$connector = new FilePrintConnector("php://stdout");
$profile = DefaultCapabilityProfile::getInstance();
$verbose = false;
// Skip tables which iconv wont convert to (ie, only print characters available with UTF-8 input)
/* Print a series of receipts containing i18n example strings - Code below shouldn't need changing */
$printer = new Escpos($connector, $profile);
$codePages = $profile->getSupportedCodePages();
$first = true;
// Print larger table for first code-page.
foreach ($codePages as $table => $name) {
    /* Change printer code page */
    $printer->selectCharacterTable(255);
    $printer->selectCharacterTable($table);
    /* Select & print a label for it */
    $label = $name;
    if ($name === false) {
        $label = " (not matched to iconv table)";
    }
    $printer->setEmphasis(true);
    $printer->textRaw("Table {$table}: {$label}\n");
    $printer->setEmphasis(false);
コード例 #26
-1
 /**
  * Convert widths and heights to characters. Used before sending graphics to set the size.
  * 
  * @param array $inputs
  * @param boolean $long True to use 4 bytes, false to use 2
  * @return string
  */
 private static function dataHeader(array $inputs, $long = true)
 {
     $outp = array();
     foreach ($inputs as $input) {
         if ($long) {
             $outp[] = Escpos::intLowHigh($input, 2);
         } else {
             self::validateInteger($input, 0, 255, __FUNCTION__);
             $outp[] = chr($input);
         }
     }
     return implode("", $outp);
 }
コード例 #27
-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();
コード例 #28
-1
ファイル: report.php プロジェクト: msd1310/ci_bootstrap
 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 */
 }
コード例 #29
-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();
コード例 #30
-2
 *      part of this example. Drop it in the folder listed below:
 */
require_once dirname(__FILE__) . "/../../Escpos.php";
require_once dirname(__FILE__) . "/../../vendor/I18N/Arabic.php";
/*
 * First, convert the text into LTR byte order with joined letters,
 * Using the Ar-PHP library.
 * 
 * The Ar-PHP library uses the default internal encoding, and can print
 * a lot of errors depending on the input, so be prepared to debug
 * the next four lines.
 * 
 * Note that this output shows that numerals are converted to placeholder
 * characters, indicating that western numerals (123) have to be used instead.
 */
mb_internal_encoding("UTF-8");
$Arabic = new I18N_Arabic('Glyphs');
$text = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
$text = $Arabic->utf8Glyphs($text);
/*
 * Set up and use the printer
 */
$buffer = new ImagePrintBuffer();
$profile = EposTepCapabilityProfile::getInstance();
$connector = new FilePrintConnector("php://output");
// = WindowsPrintConnector("LPT2");
// Windows LPT2 was used in the bug tracker
$printer = new Escpos($connector, $profile);
$printer->setPrintBuffer($buffer);
$printer->text($text . "\n");
$printer->close();