text() public method

Text should either be followed by a line-break, or feed() should be called after this to clear the print buffer.
public text ( string $str = "" )
$str string Text to print
Ejemplo n.º 1
2
function title(Printer $printer, $text)
{
    $printer->selectPrintMode(Printer::MODE_EMPHASIZED);
    $printer->text("\n" . $text);
    $printer->selectPrintMode();
    // Reset
}
 function testText()
 {
     /* Smoke test over text rendering with each profile.
      * Just makes sure we can attempt to print 'hello world' and a non-ASCII
      * char without anything blowing up */
     foreach ($this->checklist as $obj) {
         $connector = new DummyPrintConnector();
         $printer = new Printer($connector, $obj);
         $printer->text("Hello world €\n");
         $printer->close();
         // Check for character cache
         $profileName = $obj->getId();
         $expected = "Characters-{$profileName}.ser.z";
         $filename = __DIR__ . "/../../src/Mike42/Escpos/PrintBuffers/cache/{$expected}";
         $this->assertFileExists($filename);
     }
 }
Ejemplo n.º 3
2
<?php

/* Example print-outs using the older bit image print command */
require __DIR__ . '/../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
try {
    $tux = EscposImage::load("resources/tux.png", false);
    $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, Printer::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Printer::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Printer::IMG_DOUBLE_WIDTH | Printer::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();
<?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 __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\CapabilityProfiles\SimpleCapabilityProfile;
$connector = new FilePrintConnector("php://output");
$profile = SimpleCapabilityProfile::getInstance();
$printer = new Printer($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();
Ejemplo n.º 5
2
 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 Printer($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();
Ejemplo n.º 6
1
function title(Printer $printer, $str)
{
    $printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
    $printer->text($str);
    $printer->selectPrintMode();
}
Ejemplo n.º 7
1
<?php

/* Change to the correct path if you copy this example! */
require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
try {
    $connector = new CupsPrintConnector("EPSON_TM-T20");
    /* Print a "Hello world" receipt" */
    $printer = new Printer($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";
}
Ejemplo n.º 8
1
<?php

/*
 * Example of two-color printing, tested on an epson TM-U220 with two-color ribbon installed.
 */
require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector);
try {
    $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();
}
 * 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 Printer($connector, $profile);
$cmd = Printer::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
 */
Ejemplo n.º 10
1
<?php

require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile;
$connector = new FilePrintConnector("php://stdout");
$profile = DefaultCapabilityProfile::getInstance();
$printer = new Printer($connector, $profile);
$printer->text("Μιχάλης Νίκος\n");
$printer->cut();
$printer->close();
Ejemplo n.º 11
1
 * The DefaultCapabilityProfile works for Espson-branded printers. For other models, you
 * must use/create a PrinterCapabilityProfile for your printer containing a list of code
 * page numbers for your printer- otherwise you will get mojibake.
 *
 * If you do not intend to use non-English characters, then use SimpleCapabilityProfile,
 * which has only the default encoding, effectively disabling code page changes.
 */
include dirname(__FILE__) . '/resources/character-encoding-test-strings.inc';
try {
    // Enter connector and capability profile (to match your printer)
    $connector = new FilePrintConnector("php://stdout");
    $profile = DefaultCapabilityProfile::getInstance();
    /* Print a series of receipts containing i18n example strings */
    $printer = new Printer($connector, $profile);
    $printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::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);
        $printer->text($str);
    }
    $printer->feed();
    $printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
    $printer->text("Works in progress\n");
    $printer->selectPrintMode();
    foreach ($inputsNotOk as $label => $str) {
        $printer->setEmphasis(true);
        $printer->text($label . ":\n");
        $printer->setEmphasis(false);
Ejemplo n.º 12
1
<?php

require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\CapabilityProfiles\StarCapabilityProfile;
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
/* 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 Printer($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 Printer($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();
Ejemplo n.º 13
1
<?php

/* Print-outs using the newer graphics print command */
require __DIR__ . '/../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
try {
    $tux = EscposImage::load("resources/tux.png", false);
    $printer->graphics($tux);
    $printer->text("Regular Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Printer::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Printer::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Printer::IMG_DOUBLE_WIDTH | Printer::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();
Ejemplo n.º 14
1
<?php

/* Example of Greek text on the P-822D */
require __DIR__ . '/../../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\CapabilityProfiles\P822DCapabilityProfile;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
// Setup the printer
$connector = new FilePrintConnector("php://stdout");
$profile = P822DCapabilityProfile::getInstance();
$printer = new Printer($connector, $profile);
// Print a Greek pangram
$text = "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία";
$printer->text($text . "\n");
$printer->cut();
// Close the connection
$printer->close();
Ejemplo n.º 15
0
// Add connector for your printer here.
$printer = new Printer($connector);
/* Line spacing */
/*
$printer -> setEmphasis(true);
$printer -> text("Line spacing\n");
$printer -> setEmphasis(false);
foreach(array(16, 32, 64, 128, 255) as $spacing) {
    $printer -> setLineSpacing($spacing);
    $printer -> text("Spacing $spacing: The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\n");
}
$printer -> setLineSpacing(); // Back to default
*/
/* Stuff around with left margin */
$printer->setEmphasis(true);
$printer->text("Left margin\n");
$printer->setEmphasis(false);
$printer->text("Default left\n");
foreach (array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512) as $margin) {
    $printer->setPrintLeftMargin($margin);
    $printer->text("left margin {$margin}\n");
}
/* Reset left */
$printer->setPrintLeftMargin(0);
/* Stuff around with page width */
$printer->setEmphasis(true);
$printer->text("Page width\n");
$printer->setEmphasis(false);
$printer->setJustification(Printer::JUSTIFY_RIGHT);
$printer->text("Default width\n");
foreach (array(512, 256, 128, 64) as $width) {
Ejemplo n.º 16
0
$file = fopen("receipts/id.txt", "r") or die("asdsd");
$id = fgets($file);
fclose($file);
// Select customer and order info
$sql_orders = "select Order_id,o.cus_id,firstname as fname,lastname as lname,Date,Time,payed from orders as o LEFT JOIN customer_info as c ON o.cus_id = c.cus_id WHERE Order_id = {$id}";
$result = $mysql->query($sql_orders);
$row_order = $mysql->fetch($result);
if (empty($row_order['lname']) && empty($row_order['fname'])) {
    $cusname = 'Unknown';
} else {
    $cusname = $row_order['fname'] . " " . $row_order['lname'];
}
/* Print customer and order ID */
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
$printer->text("{$cusname}\n");
$printer->selectPrintMode();
$printer->text("Order# {$id}\n");
$printer->feed(2);
// Select ordered items
$sql_item_detail = "SELECT Item_id,F.order_id,cus.lastname as lname,Cs.cata_name as Food_name,Cp.Cata_name,Quantity,Cs.price as Single_Price,(Cs.price*quantity)as Total_Price,F.food_id from order_food as F JOIN orders as O on F.order_id = O.order_id JOIN food_catalogue as Cs ON F.food_id = Cs.food_id JOIN food_catalogue as Cp ON Cp.food_id = Cs.catalog_id LEFT JOIN customer_info as cus ON cus.cus_id = O.cus_id WHERE F.order_id= {$id}";
$result_item_detail = $mysql->query($sql_item_detail);
$sum = '';
while ($row_item_detail = $mysql->fetch($result_item_detail)) {
    $food_name = $row_item_detail['Food_name'];
    $qualtity = $row_item_detail['Quantity'];
    $total = $row_item_detail['Total_Price'];
    $sum = $sum + $total;
    $printer->text("{$food_name} ({$qualtity}) - {$total} RMB\n");
}
$printer->feed(2);
Ejemplo n.º 17
0
<?php

require __DIR__ . '/../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
/* Height and width */
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
$printer->text("Height and bar width\n");
$printer->selectPrintMode();
$heights = array(1, 2, 4, 8, 16, 32);
$widths = array(1, 2, 3, 4, 5, 6, 7, 8);
$printer->text("Default look\n");
$printer->barcode("ABC", Printer::BARCODE_CODE39);
foreach ($heights as $height) {
    $printer->text("\nHeight {$height}\n");
    $printer->setBarcodeHeight($height);
    $printer->barcode("ABC", Printer::BARCODE_CODE39);
}
foreach ($widths as $width) {
    $printer->text("\nWidth {$width}\n");
    $printer->setBarcodeWidth($width);
    $printer->barcode("ABC", Printer::BARCODE_CODE39);
}
$printer->feed();
// Set to something sensible for the rest of the examples
$printer->setBarcodeHeight(40);
$printer->setBarcodeWidth(2);
/* Text position */
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
Ejemplo n.º 18
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 = EscposImage::load("resources/escpos-php.png", false);
$printer = new Printer($connector);
/* Print top logo */
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->graphics($logo);
/* Name of shop */
$printer->selectPrintMode(Printer::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(Printer::JUSTIFY_LEFT);
$printer->setEmphasis(true);
$printer->text(new item('', '$'));
$printer->setEmphasis(false);
foreach ($items as $item) {
    $printer->text($item);
}
Ejemplo n.º 19
0
 *
 * 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 __DIR__ . '/../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\EscposImage;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
/* 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(Printer::MODE_FONT_B, Printer::MODE_EMPHASIZED, Printer::MODE_DOUBLE_HEIGHT, Printer::MODE_DOUBLE_WIDTH, Printer::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++) {