wip ticket printer
@ -1,26 +0,0 @@
|
||||
Examples
|
||||
--------
|
||||
|
||||
This folder contains a collectoion of feature examples.
|
||||
Generally, demo.php is the fastest way to find out which features your
|
||||
printer supports.
|
||||
|
||||
## Subfolders
|
||||
- `interface/` - contains examples for output interfaces: eg, parallel, serial, USB, network, file-based.
|
||||
- `specific/` - examples made in response to issues & questions. These cover specific languages, printers and interfaces, so hit narrower use cases.
|
||||
|
||||
## List of examples
|
||||
|
||||
Each example prints to standard output, so either edit the print connector, or redirect the output to your printer to see it in action. They are designed for developers: open them in a text editor before you run them!
|
||||
|
||||
- `bit-image.php` - Prints a images to the printer using the older "bit image" commands.
|
||||
- `demo.php` - Demonstrates output using a large subset of availale features.
|
||||
- `qr-code.php` - Prints QR codes, if your printer supports it.
|
||||
- `character-encodings.php` - Shows available character encodings. Change from the DefaultCapabilityProfile to get more useful output for your specific printer.
|
||||
- `graphics.php` - The same output as `bit-image.php`, printed with the newer graphics commands (not supported on many non-Epson printers)
|
||||
- `receipt-with-logo.php` - A simple receipt containing a logo and basic formating.
|
||||
- `character-encodings-with-images.php` - The same as `character-encodings.php`, but also prints each string using an `ImagePrintBuffer`, showing compatibility gaps.
|
||||
- `print-from-html.php` - Runs `wkhtmltoimage` to convert HTML to an image, and then prints the image. (This is very slow)
|
||||
- `character-tables.php` - Prints a compact character code table for each available character set. Used to debug incorrect output from `character-encodings.php`.
|
||||
- `print-from-pdf.php` - Loads a PDF and prints each page in a few different ways (very slow as well)
|
||||
- `rawbt-receipt` (.php & .html) - Demonstration of Back and Front for integration between the site and the Android application “RawBT - Printer Driver for Android”
|
||||
@ -1,207 +0,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);
|
||||
$printer->text("Text position\n");
|
||||
$printer->selectPrintMode();
|
||||
$hri = array (
|
||||
Printer::BARCODE_TEXT_NONE => "No text",
|
||||
Printer::BARCODE_TEXT_ABOVE => "Above",
|
||||
Printer::BARCODE_TEXT_BELOW => "Below",
|
||||
Printer::BARCODE_TEXT_ABOVE | Printer::BARCODE_TEXT_BELOW => "Both"
|
||||
);
|
||||
foreach ($hri as $position => $caption) {
|
||||
$printer->text($caption . "\n");
|
||||
$printer->setBarcodeTextPosition($position);
|
||||
$printer->barcode("012345678901", Printer::BARCODE_JAN13);
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
/* Barcode types */
|
||||
$standards = array (
|
||||
Printer::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"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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*"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_CODE93 => array (
|
||||
"title" => "Code93",
|
||||
"caption" => "Variable length- any ASCII is available",
|
||||
"example" => array (
|
||||
array (
|
||||
"caption" => "Text",
|
||||
"content" => "012abcd"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::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(Printer::BARCODE_TEXT_BELOW);
|
||||
foreach ($standards as $type => $standard) {
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::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();
|
||||
}
|
||||
}
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
@ -1,36 +0,0 @@
|
||||
<?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();
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\PrintBuffers\EscposPrintBuffer;
|
||||
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
/**
|
||||
* 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 = CapabilityProfile::load('default');
|
||||
$buffers = array(new EscposPrintBuffer(), new ImagePrintBuffer());
|
||||
|
||||
/* 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);
|
||||
foreach ($buffers as $buffer) {
|
||||
$printer -> setPrintBuffer($buffer);
|
||||
$printer -> text($str);
|
||||
}
|
||||
$printer -> setPrintBuffer($buffers[0]);
|
||||
}
|
||||
$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);
|
||||
foreach ($buffers as $buffer) {
|
||||
$printer -> setPrintBuffer($buffer);
|
||||
$printer -> text($str);
|
||||
}
|
||||
$printer -> setPrintBuffer($buffers[0]);
|
||||
}
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
/**
|
||||
* This demonstrates available character encodings. Escpos-php accepts UTF-8,
|
||||
* and converts this to lower-level data to the printer. This is a complex area, so be
|
||||
* prepared to code a model-specific hack ('CapabilityProfile') for your printer.
|
||||
*
|
||||
* If you run into trouble, please file an issue on GitHub, including at a minimum:
|
||||
* - A UTF-8 test string in the language you're working in, and
|
||||
* - A test print or link to a technical document which lists the available
|
||||
* code pages ('character code tables') for your printer.
|
||||
*
|
||||
* 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 = CapabilityProfile::load("default");
|
||||
|
||||
/* 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);
|
||||
$printer -> text($str);
|
||||
}
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This demo prints out supported code pages on your printer. This is intended
|
||||
* for debugging character-encoding issues: If your printer does not work with
|
||||
* a built-in capability profile, you need to check its documentation for
|
||||
* supported code pages.
|
||||
*
|
||||
* These are then loaded into a capability profile, which maps code page
|
||||
* 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 __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
// Enter connector and capability profile (to match your printer)
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
$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 Mike42\Escpos\Printer($connector, $profile);
|
||||
$codePages = $profile -> getCodePages();
|
||||
$first = true; // Print larger table for first code-page.
|
||||
foreach ($codePages as $table => $page) {
|
||||
/* Change printer code page */
|
||||
$printer -> selectCharacterTable(255);
|
||||
$printer -> selectCharacterTable($table);
|
||||
/* Select & print a label for it */
|
||||
$label = $page -> getId();
|
||||
if (!$page -> isEncodable()) {
|
||||
$label= " (not supported)";
|
||||
}
|
||||
$printer -> setEmphasis(true);
|
||||
$printer -> textRaw("Table $table: $label\n");
|
||||
$printer -> setEmphasis(false);
|
||||
if (!$page -> isEncodable() && !$verbose) {
|
||||
continue; // Skip non-recognised
|
||||
}
|
||||
/* Print a table of available characters (first table is larger than subsequent ones */
|
||||
if ($first) {
|
||||
$first = false;
|
||||
compactCharTable($printer, 1, true);
|
||||
} else {
|
||||
compactCharTable($printer);
|
||||
}
|
||||
}
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
function compactCharTable($printer, $start = 4, $header = false)
|
||||
{
|
||||
/* Output a compact character table for the current encoding */
|
||||
$chars = str_repeat(' ', 256);
|
||||
for ($i = 0; $i < 255; $i++) {
|
||||
$chars[$i] = ($i > 32 && $i != 127) ? chr($i) : ' ';
|
||||
}
|
||||
if ($header) {
|
||||
$printer -> setEmphasis(true);
|
||||
$printer -> textRaw(" 0123456789ABCDEF0123456789ABCDEF\n");
|
||||
$printer -> setEmphasis(false);
|
||||
}
|
||||
for ($y = $start; $y < 8; $y++) {
|
||||
$printer -> setEmphasis(true);
|
||||
$printer -> textRaw(strtoupper(dechex($y * 2)) . " ");
|
||||
$printer -> setEmphasis(false);
|
||||
$printer -> textRaw(substr($chars, $y * 32, 32) . "\n");
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This demo interacts with an Aures OCD-300 customer display,
|
||||
* showing its support for ESC/POS text encodings.
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../autoload.php';
|
||||
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\Devices\AuresCustomerDisplay;
|
||||
|
||||
/*
|
||||
* Device appears as a serial port.
|
||||
*
|
||||
* stat /dev/ttyACM0
|
||||
* sudo usermod -a -G dialout [username]
|
||||
*/
|
||||
$connector = new FilePrintConnector("/dev/ttyACM0");
|
||||
|
||||
// Profile and display
|
||||
$profile = CapabilityProfile::load("OCD-300");
|
||||
$display = new AuresCustomerDisplay($connector, $profile);
|
||||
|
||||
|
||||
// Make a really long test string
|
||||
include(__DIR__ . "/resources/character-encoding-test-strings.inc");
|
||||
$input = "";
|
||||
foreach ($inputsOk as $str) {
|
||||
$input .= $str;
|
||||
}
|
||||
|
||||
// Wrap at a fixed width (as ASCII...), and show the user
|
||||
// what's about to be sent to the printer
|
||||
$wrapped = wordwrap($input, 20);
|
||||
echo($wrapped);
|
||||
|
||||
// Roll out each line with 0.5s delay
|
||||
foreach (explode("\n", $wrapped) as $line) {
|
||||
$display -> feed();
|
||||
$display -> text($line);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
// Finish by showing "Hello World"
|
||||
$display -> clear();
|
||||
$display -> text("Hello World\n");
|
||||
|
||||
// Dont forget to close the device
|
||||
$display -> close();
|
||||
@ -1,171 +0,0 @@
|
||||
<?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 <michael.billington@gmail.com>
|
||||
*/
|
||||
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++) {
|
||||
if (substr($bits, $j, 1) == "1") {
|
||||
$mode |= $modes[$j];
|
||||
}
|
||||
}
|
||||
$printer -> selectPrintMode($mode);
|
||||
$printer -> text("ABCDEFGHIJabcdefghijk\n");
|
||||
}
|
||||
$printer -> selectPrintMode(); // Reset
|
||||
$printer -> cut();
|
||||
|
||||
/* Underline */
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$printer -> setUnderline($i);
|
||||
$printer -> text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer -> setUnderline(0); // Reset
|
||||
$printer -> cut();
|
||||
|
||||
/* Cuts */
|
||||
$printer -> text("Partial cut\n(not available on all printers)\n");
|
||||
$printer -> cut(Printer::CUT_PARTIAL);
|
||||
$printer -> text("Full cut\n");
|
||||
$printer -> cut(Printer::CUT_FULL);
|
||||
|
||||
/* Emphasis */
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$printer -> setEmphasis($i == 1);
|
||||
$printer -> text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer -> setEmphasis(false); // Reset
|
||||
$printer -> cut();
|
||||
|
||||
/* Double-strike (looks basically the same as emphasis) */
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$printer -> setDoubleStrike($i == 1);
|
||||
$printer -> text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer -> setDoubleStrike(false);
|
||||
$printer -> cut();
|
||||
|
||||
/* Fonts (many printers do not have a 'Font C') */
|
||||
$fonts = array(
|
||||
Printer::FONT_A,
|
||||
Printer::FONT_B,
|
||||
Printer::FONT_C);
|
||||
for ($i = 0; $i < count($fonts); $i++) {
|
||||
$printer -> setFont($fonts[$i]);
|
||||
$printer -> text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer -> setFont(); // Reset
|
||||
$printer -> cut();
|
||||
|
||||
/* Justification */
|
||||
$justification = array(
|
||||
Printer::JUSTIFY_LEFT,
|
||||
Printer::JUSTIFY_CENTER,
|
||||
Printer::JUSTIFY_RIGHT);
|
||||
for ($i = 0; $i < count($justification); $i++) {
|
||||
$printer -> setJustification($justification[$i]);
|
||||
$printer -> text("A man a plan a canal panama\n");
|
||||
}
|
||||
$printer -> setJustification(); // Reset
|
||||
$printer -> cut();
|
||||
|
||||
/* Barcodes - see barcode.php for more detail */
|
||||
$printer -> setBarcodeHeight(80);
|
||||
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
|
||||
$printer -> barcode("9876");
|
||||
$printer -> feed();
|
||||
$printer -> cut();
|
||||
|
||||
/* Graphics - this demo will not work on some non-Epson printers */
|
||||
try {
|
||||
$logo = EscposImage::load("resources/escpos-php.png", false);
|
||||
$imgModes = array(
|
||||
Printer::IMG_DEFAULT,
|
||||
Printer::IMG_DOUBLE_WIDTH,
|
||||
Printer::IMG_DOUBLE_HEIGHT,
|
||||
Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT
|
||||
);
|
||||
foreach ($imgModes as $mode) {
|
||||
$printer -> graphics($logo, $mode);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* Images not supported on your PHP, or image file not found */
|
||||
$printer -> text($e -> getMessage() . "\n");
|
||||
}
|
||||
$printer -> cut();
|
||||
|
||||
/* Bit image */
|
||||
try {
|
||||
$logo = EscposImage::load("resources/escpos-php.png", false);
|
||||
$imgModes = array(
|
||||
Printer::IMG_DEFAULT,
|
||||
Printer::IMG_DOUBLE_WIDTH,
|
||||
Printer::IMG_DOUBLE_HEIGHT,
|
||||
Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT
|
||||
);
|
||||
foreach ($imgModes as $mode) {
|
||||
$printer -> bitImage($logo, $mode);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* Images not supported on your PHP, or image file not found */
|
||||
$printer -> text($e -> getMessage() . "\n");
|
||||
}
|
||||
$printer -> cut();
|
||||
|
||||
/* QR Code - see also the more in-depth demo at qr-code.php */
|
||||
$testStr = "Testing 123";
|
||||
$models = array(
|
||||
Printer::QR_MODEL_1 => "QR Model 1",
|
||||
Printer::QR_MODEL_2 => "QR Model 2 (default)",
|
||||
Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)");
|
||||
foreach ($models as $model => $name) {
|
||||
$printer -> qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model);
|
||||
$printer -> text("$name\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
$printer -> cut();
|
||||
|
||||
/* Pulse */
|
||||
$printer -> pulse();
|
||||
|
||||
/* Always close the printer! On some PrintConnectors, no actual
|
||||
* data is sent until the printer is closed. */
|
||||
$printer -> close();
|
||||
@ -1,36 +0,0 @@
|
||||
<?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();
|
||||
@ -1,8 +0,0 @@
|
||||
Interfaces
|
||||
----------
|
||||
This directory contains boilerpalte code to show you how to open a print connector
|
||||
to printers which are connected in different ways.
|
||||
|
||||
To get a list of supported interfaces and operating systems, see the main README.md file for the project.
|
||||
|
||||
If you have a printer interface with no example, and you want to help put one together, then please lodge a request on the bug tracker: https://github.com/mike42/escpos-php/issues
|
||||
@ -1,19 +0,0 @@
|
||||
<?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";
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
|
||||
|
||||
/* 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 = new NetworkPrintConnector("10.x.x.x", 9100);
|
||||
|
||||
/* 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";
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/**
|
||||
* On Linux, use the usblp module to make your printer available as a device
|
||||
* file. This is generally the default behaviour if you don't install any
|
||||
* vendor drivers.
|
||||
*
|
||||
* Once this is done, use a FilePrintConnector to open the device.
|
||||
*
|
||||
* Troubleshooting: On Debian, you must be in the lp group to access this file.
|
||||
* dmesg to see what happens when you plug in your printer to make sure no
|
||||
* other drivers are unloading the module.
|
||||
*/
|
||||
try {
|
||||
// Enter the device file for your USB printer here
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
//$connector = new FilePrintConnector("/dev/usb/lp1");
|
||||
//$connector = new FilePrintConnector("/dev/usb/lp2");
|
||||
|
||||
/* 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";
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
|
||||
* then share it.
|
||||
*
|
||||
* Use a WindowsPrintConnector with the share name to print. This works on either
|
||||
* Windows or Linux.
|
||||
*
|
||||
* Troubleshooting: Fire up a command prompt/terminal, and ensure that (if your printer is
|
||||
* shared as "Receipt Printer"), the following commands work.
|
||||
*
|
||||
* Windows: (use an appropriate "net use" command if you need authentication)
|
||||
* echo "Hello World" > testfile
|
||||
* ## If you need authentication, use "net use" to hook up the printer:
|
||||
* # net use "\\computername\Receipt Printer" /user:Guest
|
||||
* # net use "\\computername\Receipt Printer" /user:Bob secret
|
||||
* # net use "\\computername\Receipt Printer" /user:workgroup\Bob secret
|
||||
* copy testfile "\\computername\Receipt Printer"
|
||||
* del testfile
|
||||
*
|
||||
* GNU/Linux:
|
||||
* # No authentication
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" -c "print -" -N
|
||||
* # Guest login
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" -U Guest -c "print -" -N
|
||||
* # Basic username/password
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "Bob" -c "print -"
|
||||
* # Including domain name
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "workgroup\\Bob" -c "print -"
|
||||
*/
|
||||
try {
|
||||
// Enter the share name for your printer here, as a smb:// url format
|
||||
$connector = new WindowsPrintConnector("smb://computername/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://Guest@computername/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://FooUser:secret@computername/workgroup/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://User:secret@computername/Receipt Printer");
|
||||
|
||||
/* 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";
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Assuming your printer is available at LPT1,
|
||||
* simpy instantiate a WindowsPrintConnector to it.
|
||||
*
|
||||
* When troubleshooting, make sure you can send it
|
||||
* data from the command-line first:
|
||||
* echo "Hello World" > LPT1
|
||||
*/
|
||||
try {
|
||||
$connector = new WindowsPrintConnector("LPT1");
|
||||
|
||||
// A FilePrintConnector will also work, but on non-Windows systems, writes
|
||||
// to an actual file called 'LPT1' rather than giving a useful error.
|
||||
// $connector = new FilePrintConnector("LPT1");
|
||||
|
||||
/* 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";
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
|
||||
* then share it (you can use a firewall so that it can only be seen locally).
|
||||
*
|
||||
* Use a WindowsPrintConnector with the share name to print.
|
||||
*
|
||||
* Troubleshooting: Fire up a command prompt, and ensure that (if your printer is shared as
|
||||
* "Receipt Printer), the following commands work:
|
||||
*
|
||||
* echo "Hello World" > testfile
|
||||
* copy testfile "\\%COMPUTERNAME%\Receipt Printer"
|
||||
* del testfile
|
||||
*/
|
||||
try {
|
||||
// Enter the share name for your USB printer here
|
||||
$connector = null;
|
||||
//$connector = new WindowsPrintConnector("Receipt Printer");
|
||||
|
||||
/* 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";
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/* Left margin & page width demo. */
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout"); // 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) {
|
||||
$printer -> setPrintWidth($width);
|
||||
$printer -> text("page width $width\n");
|
||||
}
|
||||
|
||||
/* Printer shutdown */
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/* Demonstration of available options on the pdf417Code() command */
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Most simple example
|
||||
title($printer, "PDF417 code demo\n");
|
||||
$testStr = "Testing 123";
|
||||
$printer -> pdf417Code($testStr);
|
||||
$printer -> text("Most simple example\n");
|
||||
$printer -> feed();
|
||||
|
||||
// Demo that alignment is the same as text
|
||||
$printer -> setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer -> pdf417Code($testStr, 3, 3, 2);
|
||||
$printer -> text("Same content, narrow and centred\n");
|
||||
$printer -> setJustification();
|
||||
$printer -> feed();
|
||||
|
||||
// Demo of error correction
|
||||
title($printer, "Error correction\n");
|
||||
$ec = array(0.1, 0.5, 1.0, 2.0, 4.0);
|
||||
foreach ($ec as $level) {
|
||||
$printer -> pdf417Code($testStr, 3, 3, 0, $level);
|
||||
$printer -> text("Error correction ratio $level\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Change size
|
||||
title($printer, "Pixel size\n");
|
||||
$sizes = array(
|
||||
2 => "(minimum)",
|
||||
3 => "(default)",
|
||||
4 => "",
|
||||
8 => "(maximum)");
|
||||
foreach ($sizes as $size => $label) {
|
||||
$printer -> pdf417Code($testStr, $size);
|
||||
$printer -> text("Module width $size dots $label\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Change height
|
||||
title($printer, "Height multiplier\n");
|
||||
$sizes = array(
|
||||
2 => "(minimum)",
|
||||
3 => "(default)",
|
||||
4 => "",
|
||||
8 => "(maximum)");
|
||||
foreach ($sizes as $size => $label) {
|
||||
$printer -> pdf417Code($testStr, 3, $size);
|
||||
$printer -> text("Height multiplier $size $label\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Chage data column count
|
||||
title($printer, "Data column count\n");
|
||||
$columnCounts = array(
|
||||
0 => "(auto, default)",
|
||||
1 => "",
|
||||
2 => "",
|
||||
3 => "",
|
||||
4 => "",
|
||||
5 => "",
|
||||
30 => "(maximum, doesnt fit!)");
|
||||
foreach ($columnCounts as $columnCount => $label) {
|
||||
$printer -> pdf417Code($testStr, 3, 3, $columnCount);
|
||||
$printer -> text("Column count $columnCount $label\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Change options
|
||||
title($printer, "Options\n");
|
||||
$models = array(
|
||||
Printer::PDF417_STANDARD => "Standard",
|
||||
Printer::PDF417_TRUNCATED => "Truncated");
|
||||
foreach ($models as $model => $name) {
|
||||
$printer -> pdf417Code($testStr, 3, 3, 0, 0.10, $model);
|
||||
$printer -> text("$name\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Cut & close
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
function title(Printer $printer, $str)
|
||||
{
|
||||
$printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer -> text($str);
|
||||
$printer -> selectPrintMode();
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout"); // Add connector for your printer here.
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/*
|
||||
* Due to its complxity, escpos-php does not support HTML input. To print HTML,
|
||||
* either convert it to calls on the Printer() object, or rasterise the page with
|
||||
* wkhtmltopdf, an external package which is designed to handle HTML efficiently.
|
||||
*
|
||||
* This example is provided to get you started: On Debian, first run-
|
||||
*
|
||||
* sudo apt-get install wkhtmltopdf xvfb
|
||||
*
|
||||
* Note: Depending on the height of your pages, it is suggested that you chop it
|
||||
* into smaller sections, as printers simply don't have the buffer capacity for
|
||||
* very large images.
|
||||
*
|
||||
* As always, you can trade off quality for capacity by halving the width
|
||||
* (550 -> 225 below) and printing w/ Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT
|
||||
*/
|
||||
try {
|
||||
/* Set up command */
|
||||
$source = __DIR__ . "/resources/document.html";
|
||||
$width = 550;
|
||||
$dest = tempnam(sys_get_temp_dir(), 'escpos') . ".png";
|
||||
$command = sprintf(
|
||||
"xvfb-run wkhtmltoimage -n -q --width %s %s %s",
|
||||
escapeshellarg($width),
|
||||
escapeshellarg($source),
|
||||
escapeshellarg($dest)
|
||||
);
|
||||
|
||||
/* Test for dependencies */
|
||||
foreach (array("xvfb-run", "wkhtmltoimage") as $cmd) {
|
||||
$testCmd = sprintf("which %s", escapeshellarg($cmd));
|
||||
exec($testCmd, $testOut, $testStatus);
|
||||
if ($testStatus != 0) {
|
||||
throw new Exception("You require $cmd but it could not be found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Run wkhtmltoimage */
|
||||
$descriptors = array(
|
||||
1 => array("pipe", "w"),
|
||||
2 => array("pipe", "w"),
|
||||
);
|
||||
$process = proc_open($command, $descriptors, $fd);
|
||||
if (is_resource($process)) {
|
||||
/* Read stdout */
|
||||
$outputStr = stream_get_contents($fd[1]);
|
||||
fclose($fd[1]);
|
||||
/* Read stderr */
|
||||
$errorStr = stream_get_contents($fd[2]);
|
||||
fclose($fd[2]);
|
||||
/* Finish up */
|
||||
$retval = proc_close($process);
|
||||
if ($retval != 0) {
|
||||
throw new Exception("Command $cmd failed: $outputStr $errorStr");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Command '$cmd' failed to start.");
|
||||
}
|
||||
|
||||
/* Load up the image */
|
||||
try {
|
||||
$img = EscposImage::load($dest);
|
||||
} catch (Exception $e) {
|
||||
unlink($dest);
|
||||
throw $e;
|
||||
}
|
||||
unlink($dest);
|
||||
|
||||
/* Print it */
|
||||
$printer -> bitImage($img); // bitImage() seems to allow larger images than graphics() on the TM-T20. bitImageColumnFormat() is another option.
|
||||
$printer -> cut();
|
||||
} catch (Exception $e) {
|
||||
echo $e -> getMessage();
|
||||
} finally {
|
||||
$printer -> close();
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\ImagickEscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/*
|
||||
* This is three examples in one:
|
||||
* 1: Print an entire PDF, normal quality.
|
||||
* 2: Print at a lower quality for speed increase (CPU & transfer)
|
||||
* 3: Cache rendered documents for a speed increase (removes CPU image processing completely on subsequent prints)
|
||||
*/
|
||||
|
||||
/* 1: Print an entire PDF, start-to-finish (shorter form of the example) */
|
||||
$pdf = 'resources/document.pdf';
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
try {
|
||||
$pages = ImagickEscposImage::loadPdf($pdf);
|
||||
foreach ($pages as $page) {
|
||||
$printer -> graphics($page);
|
||||
}
|
||||
$printer -> cut();
|
||||
} catch (Exception $e) {
|
||||
/*
|
||||
* loadPdf() throws exceptions if files or not found, or you don't have the
|
||||
* imagick extension to read PDF's
|
||||
*/
|
||||
echo $e -> getMessage() . "\n";
|
||||
} finally {
|
||||
$printer -> close();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 2: Speed up printing by roughly halving the resolution, and printing double-size.
|
||||
* This gives a 75% speed increase at the expense of some quality.
|
||||
*
|
||||
* Reduce the page width further if necessary: if it extends past the printing area, your prints will be very slow.
|
||||
*/
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$pdf = 'resources/document.pdf';
|
||||
$pages = ImagickEscposImage::loadPdf($pdf, 260);
|
||||
foreach ($pages as $page) {
|
||||
$printer -> graphics($page, Printer::IMG_DOUBLE_HEIGHT | Printer::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.
|
||||
*/
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$pdf = 'resources/document.pdf';
|
||||
$ser = 'resources/document.z';
|
||||
if (!file_exists($ser)) {
|
||||
$pages = ImagickEscposImage::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)));
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
/* Demonstration of available options on the qrCode() command */
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Most simple example
|
||||
title($printer, "QR code demo\n");
|
||||
$testStr = "Testing 123";
|
||||
$printer -> qrCode($testStr);
|
||||
$printer -> text("Most simple example\n");
|
||||
$printer -> feed();
|
||||
|
||||
// Demo that alignment is the same as text
|
||||
$printer -> setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer -> qrCode($testStr);
|
||||
$printer -> text("Same example, centred\n");
|
||||
$printer -> setJustification();
|
||||
$printer -> feed();
|
||||
|
||||
// Demo of numeric data being packed more densly
|
||||
title($printer, "Data encoding\n");
|
||||
$test = array(
|
||||
"Numeric" => "0123456789012345678901234567890123456789",
|
||||
"Alphanumeric" => "abcdefghijklmnopqrstuvwxyzabcdefghijklmn",
|
||||
"Binary" => str_repeat("\0", 40));
|
||||
foreach ($test as $type => $data) {
|
||||
$printer -> qrCode($data);
|
||||
$printer -> text("$type\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Demo of error correction
|
||||
title($printer, "Error correction\n");
|
||||
$ec = array(
|
||||
Printer::QR_ECLEVEL_L => "L",
|
||||
Printer::QR_ECLEVEL_M => "M",
|
||||
Printer::QR_ECLEVEL_Q => "Q",
|
||||
Printer::QR_ECLEVEL_H => "H");
|
||||
foreach ($ec as $level => $name) {
|
||||
$printer -> qrCode($testStr, $level);
|
||||
$printer -> text("Error correction $name\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Change size
|
||||
title($printer, "Pixel size\n");
|
||||
$sizes = array(
|
||||
1 => "(minimum)",
|
||||
2 => "",
|
||||
3 => "(default)",
|
||||
4 => "",
|
||||
5 => "",
|
||||
10 => "",
|
||||
16 => "(maximum)");
|
||||
foreach ($sizes as $size => $label) {
|
||||
$printer -> qrCode($testStr, Printer::QR_ECLEVEL_L, $size);
|
||||
$printer -> text("Pixel size $size $label\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Change model
|
||||
title($printer, "QR model\n");
|
||||
$models = array(
|
||||
Printer::QR_MODEL_1 => "QR Model 1",
|
||||
Printer::QR_MODEL_2 => "QR Model 2 (default)",
|
||||
Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)");
|
||||
foreach ($models as $model => $name) {
|
||||
$printer -> qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model);
|
||||
$printer -> text("$name\n");
|
||||
$printer -> feed();
|
||||
}
|
||||
|
||||
// Cut & close
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
function title(Printer $printer, $str)
|
||||
{
|
||||
$printer -> selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer -> text($str);
|
||||
$printer -> selectPrintMode();
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>RawBT Integration Demo</title>
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
<style>
|
||||
html {
|
||||
background-color: grey;
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
body {
|
||||
max-width: 640px;
|
||||
margin: 0 auto;
|
||||
padding: 32px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #6e89ff;
|
||||
color: white;
|
||||
padding: 16px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #f0f0f0;
|
||||
border-left: #6e89ff solid 3px
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #6e89ff;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:before{
|
||||
content: '\1F855';
|
||||
margin-right:4px;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
// for php demo call
|
||||
function ajax_print(url, btn) {
|
||||
b = $(btn);
|
||||
b.attr('data-old', b.text());
|
||||
b.text('wait');
|
||||
$.get(url, function (data) {
|
||||
window.location.href = data; // main action
|
||||
}).fail(function () {
|
||||
alert("ajax error");
|
||||
}).always(function () {
|
||||
b.text(b.attr('data-old'));
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<img src="resources/rawbtlogo.png" alt="black & white picture">
|
||||
<h1>RawBT Integration Demo</h1>
|
||||
<pre>
|
||||
|
||||
window.location.href = ajax_backend_data;
|
||||
|
||||
</pre>
|
||||
<br/>
|
||||
<button onclick="ajax_print('rawbt-receipt.php',this)">RECEIPT</button>
|
||||
|
||||
<p><a href="https://rawbt.ru/">Visit RawBT site</a></p>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../autoload.php';
|
||||
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\RawbtPrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
try {
|
||||
$profile = CapabilityProfile::load("POS-5890");
|
||||
|
||||
/* Fill in your own connector here */
|
||||
$connector = new RawbtPrintConnector();
|
||||
|
||||
/* 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 = EscposImage::load("resources/rawbtlogo.png", false);
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
|
||||
/* Print top logo */
|
||||
if ($profile->getSupportsGraphics()) {
|
||||
$printer->graphics($logo);
|
||||
}
|
||||
if ($profile->getSupportsBitImageRaster() && !$profile->getSupportsGraphics()) {
|
||||
$printer->bitImage($logo);
|
||||
}
|
||||
|
||||
/* Name of shop */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$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->getAsString(32)); // for 58mm Font A
|
||||
}
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($subtotal->getAsString(32));
|
||||
$printer->setEmphasis(false);
|
||||
$printer->feed();
|
||||
|
||||
/* Tax and total */
|
||||
$printer->text($tax->getAsString(32));
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($total->getAsString(32));
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Footer */
|
||||
$printer->feed(2);
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->text("Thank you for shopping\n");
|
||||
$printer->text("at ExampleMart\n");
|
||||
$printer->text("For trading hours,\n");
|
||||
$printer->text("please visit example.com\n");
|
||||
$printer->feed(2);
|
||||
$printer->text($date . "\n");
|
||||
|
||||
/* Barcode Default look */
|
||||
|
||||
$printer->barcode("ABC", Printer::BARCODE_CODE39);
|
||||
$printer->feed();
|
||||
$printer->feed();
|
||||
|
||||
|
||||
// Demo that alignment QRcode is the same as text
|
||||
$printer2 = new Printer($connector); // dirty printer profile hack !!
|
||||
$printer2->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer2->qrCode("https://rawbt.ru/mike42", Printer::QR_ECLEVEL_M, 8);
|
||||
$printer2->text("rawbt.ru/mike42\n");
|
||||
$printer2->setJustification();
|
||||
$printer2->feed();
|
||||
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
} finally {
|
||||
$printer->close();
|
||||
}
|
||||
|
||||
/* A wrapper to do organise item names & prices into columns */
|
||||
|
||||
class item
|
||||
{
|
||||
private $name;
|
||||
private $price;
|
||||
private $dollarSign;
|
||||
|
||||
public function __construct($name = '', $price = '', $dollarSign = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->price = $price;
|
||||
$this->dollarSign = $dollarSign;
|
||||
}
|
||||
|
||||
public function getAsString($width = 48)
|
||||
{
|
||||
$rightCols = 10;
|
||||
$leftCols = $width - $rightCols;
|
||||
if ($this->dollarSign) {
|
||||
$leftCols = $leftCols / 2 - $rightCols / 2;
|
||||
}
|
||||
$left = str_pad($this->name, $leftCols);
|
||||
|
||||
$sign = ($this->dollarSign ? '$ ' : '');
|
||||
$right = str_pad($sign . $this->price, $rightCols, ' ', STR_PAD_LEFT);
|
||||
return "$left$right\n";
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getAsString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/* Fill in your own connector here */
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
|
||||
/* 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 = 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);
|
||||
}
|
||||
$printer -> setEmphasis(true);
|
||||
$printer -> text($subtotal);
|
||||
$printer -> setEmphasis(false);
|
||||
$printer -> feed();
|
||||
|
||||
/* Tax and total */
|
||||
$printer -> text($tax);
|
||||
$printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer -> text($total);
|
||||
$printer -> selectPrintMode();
|
||||
|
||||
/* Footer */
|
||||
$printer -> feed(2);
|
||||
$printer -> setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer -> text("Thank you for shopping at ExampleMart\n");
|
||||
$printer -> text("For trading hours, please visit example.com\n");
|
||||
$printer -> feed(2);
|
||||
$printer -> text($date . "\n");
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer -> cut();
|
||||
$printer -> pulse();
|
||||
|
||||
$printer -> close();
|
||||
|
||||
/* A wrapper to do organise item names & prices into columns */
|
||||
class item
|
||||
{
|
||||
private $name;
|
||||
private $price;
|
||||
private $dollarSign;
|
||||
|
||||
public function __construct($name = '', $price = '', $dollarSign = false)
|
||||
{
|
||||
$this -> name = $name;
|
||||
$this -> price = $price;
|
||||
$this -> dollarSign = $dollarSign;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$rightCols = 10;
|
||||
$leftCols = 38;
|
||||
if ($this -> dollarSign) {
|
||||
$leftCols = $leftCols / 2 - $rightCols / 2;
|
||||
}
|
||||
$left = str_pad($this -> name, $leftCols) ;
|
||||
|
||||
$sign = ($this -> dollarSign ? '$ ' : '');
|
||||
$right = str_pad($sign . $this -> price, $rightCols, ' ', STR_PAD_LEFT);
|
||||
return "$left$right\n";
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/* All strings from EscposPrintBufferTest are included below- These are fully supported
|
||||
* on the default profile, so you can use them to test modified profiles (using the wrong
|
||||
* profile for a printer produces mojibake) */
|
||||
$inputsOk = array(
|
||||
"Danish" => "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n",
|
||||
"German" => "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n",
|
||||
"Greek" => "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία\n",
|
||||
"English" => "The quick brown fox jumps over the lazy dog.\n",
|
||||
"Spanish" => "El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n",
|
||||
"French" => "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n",
|
||||
"Irish Gaelic" => "D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n",
|
||||
"Hungarian" => "Árvíztűrő tükörfúrógép.\n",
|
||||
"Icelandic" => "Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa.\n",
|
||||
"Latvian" => "Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n",
|
||||
"Polish" => "Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n",
|
||||
"Russian" => "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n",
|
||||
"Turkish" => "Pijamalı hasta, yağız şoföre çabucak güvendi.\n",
|
||||
"Japanese (Katakana half-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n",
|
||||
"Vietnamese" => "Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n"
|
||||
);
|
||||
|
||||
/*
|
||||
* These strings are not expected to print correctly, if at all, even on an Epson printer. This is due to a mix of
|
||||
* escpos driver, printer, and PHP language support issues.
|
||||
*
|
||||
* They are included here as a collection of things not yet implemented.
|
||||
*/
|
||||
$inputsNotOk = array(
|
||||
"Thai (No character encoder available)" => "นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n",
|
||||
"Japanese (Hiragana)" => implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n",
|
||||
"Japanese (Katakana full-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n",
|
||||
"Arabic (RTL not supported, encoding issues)" => "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n",
|
||||
"Hebrew (RTL not supported, line break issues)" => "דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n"
|
||||
);
|
||||
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 370 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$a = "{A012323392982";
|
||||
$b = "{B012323392982";
|
||||
$c = "{C" . chr(01) . chr(23) . chr(23) . chr(39) . chr(29) . chr(82);
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$printer -> setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer -> setBarcodeHeight(48);
|
||||
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
|
||||
foreach(array($a, $b, $c) as $item) {
|
||||
$printer -> barcode($item, Printer::BARCODE_CODE128);
|
||||
$printer -> feed(1);
|
||||
}
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile;
|
||||
|
||||
/**
|
||||
* This example shows how to send a custom command to the printer
|
||||
*
|
||||
* "ESC ( B" is the barcode function for Epson LX300 series.
|
||||
* This is not part of standard ESC/POS, but it's a good example
|
||||
* of how to send some binary to the driver.
|
||||
*/
|
||||
|
||||
/* Barcode type is used in this script */
|
||||
const EAN13 = 0;
|
||||
|
||||
/* Barcode properties */
|
||||
$type = EAN13;
|
||||
$content = "0075678164125";
|
||||
|
||||
/*
|
||||
* Make the command.
|
||||
* This is documented on page A-14 of:
|
||||
* https://files.support.epson.com/pdf/lx300p/lx300pu1.pdf
|
||||
*/
|
||||
$m = chr(EAN13);
|
||||
$n = intLowHigh(strlen($content), 2);
|
||||
$barcodeCommand = Printer::ESC . "G(" . $m . $n . $content;
|
||||
|
||||
/* Send it off as usual */
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$printer = new Printer($connector);
|
||||
$printer->getPrintConnector()->write($barcodeCommand);
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/**
|
||||
* Generate two characters for a number: In lower and higher parts, or more parts as needed.
|
||||
*
|
||||
* @param int $input
|
||||
* Input number
|
||||
* @param int $length
|
||||
* The number of bytes to output (1 - 4).
|
||||
*/
|
||||
function intLowHigh($input, $length)
|
||||
{
|
||||
$outp = "";
|
||||
for ($i = 0; $i < $length; $i ++) {
|
||||
$outp .= chr($input % 256);
|
||||
$input = (int) ($input / 256);
|
||||
}
|
||||
return $outp;
|
||||
}
|
||||
?>
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of one way you could load a PNG data URI into an EscposImage object
|
||||
* without using a file.
|
||||
*/
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\ImagickEscposImage;
|
||||
|
||||
// Data URI for a PNG image (red dot from https://en.wikipedia.org/wiki/Data_URI_scheme )
|
||||
$uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
|
||||
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
|
||||
9TXL0Y4OHwAAAABJRU5ErkJggg==";
|
||||
|
||||
// Convert data URI to binary data
|
||||
$imageBlob = base64_decode(explode(",", $uri)[1]);
|
||||
|
||||
// Give Imagick a filename with the correct extension to stop it from attempting
|
||||
// to identify the format itself (this avoids CVE-2016–3714)
|
||||
$imagick = new Imagick();
|
||||
$imagick -> setResourceLimit(6, 1); // Prevent libgomp1 segfaults, grumble grumble.
|
||||
$imagick -> readImageBlob($imageBlob, "input.png");
|
||||
|
||||
// Load Imagick straight into an EscposImage object
|
||||
$im = new ImagickEscposImage();
|
||||
$im -> readImageFromImagick($imagick);
|
||||
|
||||
// Do a test print to make sure that this EscposImage object has the right data
|
||||
// (should see a tiny bullet point)
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$printer = new Printer($connector);
|
||||
$printer -> bitImage($im);
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Example showing how to return binary data back to the user.
|
||||
*
|
||||
* This is intended for the "Star TSP650IIcloudPRNT" printer.
|
||||
*/
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
// Make sure you load a Star print connector or you may get gibberish.
|
||||
$connector = new DummyPrintConnector();
|
||||
$profile = CapabilityProfile::load("TSP600");
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello world!\n");
|
||||
$printer -> cut();
|
||||
|
||||
// Get the data out as a string
|
||||
$data = $connector -> getData();
|
||||
|
||||
// Return it, check the manual for specifics.
|
||||
header('Content-type: application/octet-stream');
|
||||
header('Content-Length: '.strlen($data));
|
||||
echo $data;
|
||||
|
||||
// Close the printer when done.
|
||||
$printer -> close();
|
||||
@ -1,25 +0,0 @@
|
||||
<?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();
|
||||
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/*
|
||||
* This example shows how tok send a custom command to the printer-
|
||||
* 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 = CapabilityProfile::load("default"); // 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
|
||||
*/
|
||||
@ -1,19 +0,0 @@
|
||||
<?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\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$profile = CapabilityProfile::load("simple"); // Works for Epson printers
|
||||
$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();
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This is an example of printing chinese text. This is a bit different to other character encodings, because
|
||||
* the printer accepts a 2-byte character encoding (GBK), and formatting is handled differently while in this mode.
|
||||
*
|
||||
* At the time of writing, this is implemented separately as a textChinese() function, until chinese text
|
||||
* can be properly detected and printed alongside other encodings.
|
||||
*/
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp1");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Example text from #37
|
||||
$printer -> textChinese("艾德蒙 AOC E2450SWH 23.6吋 LED液晶寬螢幕特價$ 19900\n\n");
|
||||
|
||||
// Note that on the printer tested (ZJ5890), the font only contained simplified characters.
|
||||
$printer -> textChinese("示例文本打印机!\n\n");
|
||||
$printer -> close();
|
||||
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
$profile = CapabilityProfile::load("default");
|
||||
// This is a quick demo of currency symbol issues in #39.
|
||||
|
||||
/* Option 1: Native ESC/POS characters, depends on printer and is buggy. */
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$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();
|
||||
|
||||
/* 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("€ 9,95\n");
|
||||
$printer -> text("£ 9.95\n");
|
||||
$printer -> text("$ 9.95\n");
|
||||
$printer -> text("¥ 9.95\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
/*
|
||||
Option 3: If the printer is configured to print in a specific code
|
||||
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 CapabilityProfile
|
||||
{
|
||||
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();
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/* Example of printing the GBP pound symbol on a STAR TSP650
|
||||
*
|
||||
* In this example, it's shown how to check that your PHP files are actually being
|
||||
* saved in unicode. Sections B) and C) are identical in UTF-8, but different
|
||||
* if you are saving to a retro format like Windows-1252.
|
||||
*/
|
||||
|
||||
// Adjust these to your environment
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
|
||||
// Start printer
|
||||
$profile = CapabilityProfile::load("simple");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
// A) Raw pound symbol
|
||||
// This is the most likely thing to work, and bypasses all the fancy stuff.
|
||||
$printer -> textRaw("\x9C"); // based on position in CP437
|
||||
$printer -> text(" 1.95\n");
|
||||
|
||||
// B) Manually encoded UTF8 pound symbol. Tests that the driver correctly
|
||||
// encodes this as CP437.
|
||||
$printer -> text(base64_decode("wqM=") . " 2.95\n");
|
||||
|
||||
// C) Pasted in file. Tests that your files are being saved as UTF-8, which
|
||||
// escpos-php is able to convert automatically to a mix of code pages.
|
||||
$printer -> text("£ 3.95\n");
|
||||
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
/* Example of Greek text on the P-822D */
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
// Setup the printer
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("P822D");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
// Print a Greek pangram
|
||||
$text = "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία";
|
||||
$printer -> text($text . "\n");
|
||||
$printer -> cut();
|
||||
|
||||
// Close the connection
|
||||
$printer -> close();
|
||||
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of calling ImageMagick 'convert' to manipulate an image prior to printing.
|
||||
*
|
||||
* Written as an example to remind you to do four things-
|
||||
* - escape your command-line arguments with escapeshellarg
|
||||
* - close the printer
|
||||
* - delete any temp files
|
||||
* - detect and handle external command failure
|
||||
*
|
||||
* Note that image operations are slow. You can and should serialise an EscposImage
|
||||
* object into some sort of cache if you will re-use the output.
|
||||
*/
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
// Paths to images to combine
|
||||
$img1_path = dirname(__FILE__) . "/../resources/tux.png";
|
||||
$img2_path = dirname(__FILE__) . "/../resources/escpos-php.png";
|
||||
|
||||
// Set up temp file with .png extension
|
||||
$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 = EscposImage::load($imgCombined_path);
|
||||
|
||||
// Setup the printer
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
|
||||
// Run the actual print
|
||||
$printer = new Printer($connector, $profile);
|
||||
try {
|
||||
$printer -> setJustification(Printer::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);
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This example shows Arabic image-based output on the EPOS TEP 220m.
|
||||
*
|
||||
* Because escpos-php is not yet able to render Arabic correctly
|
||||
* on thermal line printers, small images are generated and sent
|
||||
* instead. This is a bit slower, and only limited formatting
|
||||
* is currently available in this mode.
|
||||
*
|
||||
* Requirements are:
|
||||
* - imagick extension (For the ImagePrintBuffer, which does not
|
||||
* support gd at the time of writing)
|
||||
* - ArPHP 4.0 (release date: Jan 8, 2016), available from SourceForge, for
|
||||
* handling the layout for this example.
|
||||
*/
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
/*
|
||||
* Drop Ar-php into the folder listed below:
|
||||
*/
|
||||
require_once(dirname(__FILE__) . "/../../I18N/Arabic.php");
|
||||
$fontPath = dirname(__FILE__) . "/../../I18N/Arabic/Examples/GD/ae_AlHor.ttf";
|
||||
|
||||
/*
|
||||
* Inputs are some text, line wrapping options, and a font size.
|
||||
*/
|
||||
$textUtf8 = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
|
||||
$maxChars = 50;
|
||||
$fontSize = 28;
|
||||
|
||||
/*
|
||||
* First, convert the text into LTR byte order with line wrapping,
|
||||
* 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');
|
||||
$textLtr = $Arabic -> utf8Glyphs($textUtf8, $maxChars);
|
||||
$textLine = explode("\n", $textLtr);
|
||||
|
||||
/*
|
||||
* Set up and use an image print buffer with a suitable font
|
||||
*/
|
||||
$buffer = new ImagePrintBuffer();
|
||||
$buffer -> setFont($fontPath);
|
||||
$buffer -> setFontSize($fontSize);
|
||||
|
||||
$profile = CapabilityProfile::load("TEP-200M");
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
// = new WindowsPrintConnector("LPT2");
|
||||
// Windows LPT2 was used in the bug tracker
|
||||
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> setPrintBuffer($buffer);
|
||||
|
||||
$printer -> setJustification(Printer::JUSTIFY_RIGHT);
|
||||
foreach($textLine as $text) {
|
||||
// Print each line separately. We need to do this since Imagick thinks
|
||||
// text is left-to-right
|
||||
$printer -> text($text . "\n");
|
||||
}
|
||||
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
$printer -> text("Μιχάλης Νίκος\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
?>
|
||||
@ -1,21 +0,0 @@
|
||||
<?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(Printer::COLOR_2);
|
||||
$printer -> text("Red?!\n");
|
||||
$printer -> setColor(Printer::COLOR_1);
|
||||
$printer -> text("Default color again?!\n");
|
||||
$printer -> cut();
|
||||
} finally {
|
||||
/* Always close the printer! */
|
||||
$printer -> close();
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of dithering used in EscposImage by default, if you have Imagick loaded.
|
||||
*/
|
||||
require __DIR__ . '/../../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
$printer = new Printer($connector);
|
||||
try {
|
||||
/* Load with optimisations enabled. If you have Imagick, this will get you
|
||||
a nicely dithered image, which prints very quickly
|
||||
*/
|
||||
$img1 = EscposImage::load(__DIR__ . '/../resources/tulips.png');
|
||||
$printer -> bitImage($img1);
|
||||
|
||||
/* Load with optimisations disabled, forcing the use of PHP to convert the
|
||||
pixels, which uses a threshold and is much slower.
|
||||
*/
|
||||
$img2 = EscposImage::load(__DIR__ . '/../resources/tulips.png', false);
|
||||
$printer -> bitImage($img2);
|
||||
$printer -> cut();
|
||||
} finally {
|
||||
/* Always close the printer! */
|
||||
$printer -> close();
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
Specific examples
|
||||
-----------------
|
||||
|
||||
These examples are designed for specific combinations of language,
|
||||
printer and interface.
|
||||
|
||||
They are documented here because the general examples all set up the printer in a similar way.
|
||||
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This print-out shows how large the available font sizes are. It is included
|
||||
* separately due to the amount of text it prints.
|
||||
*
|
||||
* @author Michael Billington <michael.billington@gmail.com>
|
||||
*/
|
||||
require __DIR__ . '/../autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Initialize */
|
||||
$printer -> initialize();
|
||||
|
||||
/* Text of various (in-proportion) sizes */
|
||||
title($printer, "Change height & width\n");
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
$printer -> setTextSize($i, $i);
|
||||
$printer -> text($i);
|
||||
}
|
||||
$printer -> text("\n");
|
||||
|
||||
/* Width changing only */
|
||||
title($printer, "Change width only (height=4):\n");
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
$printer -> setTextSize($i, 4);
|
||||
$printer -> text($i);
|
||||
}
|
||||
$printer -> text("\n");
|
||||
|
||||
/* Height changing only */
|
||||
title($printer, "Change height only (width=4):\n");
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
$printer -> setTextSize(4, $i);
|
||||
$printer -> text($i);
|
||||
}
|
||||
$printer -> text("\n");
|
||||
|
||||
/* Very narrow text */
|
||||
title($printer, "Very narrow text:\n");
|
||||
$printer -> setTextSize(1, 8);
|
||||
$printer -> text("The quick brown fox jumps over the lazy dog.\n");
|
||||
|
||||
/* Very flat text */
|
||||
title($printer, "Very wide text:\n");
|
||||
$printer -> setTextSize(4, 1);
|
||||
$printer -> text("Hello world!\n");
|
||||
|
||||
/* Very large text */
|
||||
title($printer, "Largest possible text:\n");
|
||||
$printer -> setTextSize(8, 8);
|
||||
$printer -> text("Hello\nworld!\n");
|
||||
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
function title(Printer $printer, $text)
|
||||
{
|
||||
$printer -> selectPrintMode(Printer::MODE_EMPHASIZED);
|
||||
$printer -> text("\n" . $text);
|
||||
$printer -> selectPrintMode(); // Reset
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$composer_autoload = __DIR__ . "/../vendor/autoload.php";
|
||||
$standalone_autoload = __DIR__ . "/../autoload.php";
|
||||
|
||||
if (file_exists($composer_autoload)) {
|
||||
require_once($composer_autoload);
|
||||
} else {
|
||||
require_once($standalone_autoload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in many of the tests to to output known-correct
|
||||
* strings for use in tests.
|
||||
*/
|
||||
function friendlyBinary($in)
|
||||
{
|
||||
if (is_array($in)) {
|
||||
$out = array();
|
||||
foreach ($in as $line) {
|
||||
$out[] = friendlyBinary($line);
|
||||
}
|
||||
return "[" . implode(", ", $out) . "]";
|
||||
}
|
||||
if (strlen($in) == 0) {
|
||||
return $in;
|
||||
}
|
||||
/* Print out binary data with PHP \x00 escape codes,
|
||||
for builting test cases. */
|
||||
$chars = str_split($in);
|
||||
foreach ($chars as $i => $c) {
|
||||
$code = ord($c);
|
||||
if ($code < 32 || $code > 126) {
|
||||
$chars[$i] = "\\x" . bin2hex($c);
|
||||
}
|
||||
}
|
||||
return implode($chars);
|
||||
}
|
||||
@ -1,187 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class ExampleTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/* Verify that the examples don't fizzle out with fatal errors */
|
||||
private $exampleDir;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this -> exampleDir = dirname(__FILE__) . "/../../example/";
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBitImage()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("bit-image.php");
|
||||
$this -> outpTest($outp, "bit-image.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testCharacterEncodings()
|
||||
{
|
||||
$outp = $this -> runExample("character-encodings.php");
|
||||
$this -> outpTest($outp, "character-encodings.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testCharacterTables()
|
||||
{
|
||||
$outp = $this -> runExample("character-tables.php");
|
||||
$this -> outpTest($outp, "character-tables.bin");
|
||||
}
|
||||
|
||||
private function outpTest($outp, $fn)
|
||||
{
|
||||
$file = dirname(__FILE__) . "/resources/output/".$fn;
|
||||
if (!file_exists($file)) {
|
||||
file_put_contents($file, $outp);
|
||||
}
|
||||
$this -> assertEquals($outp, file_get_contents($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testDemo()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("demo.php");
|
||||
$this -> outpTest($outp, "demo.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGraphics()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("graphics.php");
|
||||
$this -> outpTest($outp, "graphics.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testReceiptWithLogo()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("receipt-with-logo.php");
|
||||
$this -> outpTest($outp, "receipt-with-logo.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testQrCode()
|
||||
{
|
||||
$outp = $this -> runExample("qr-code.php");
|
||||
$this -> outpTest($outp, "qr-code.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBarcode()
|
||||
{
|
||||
$outp = $this -> runExample("barcode.php");
|
||||
$this -> outpTest($outp, "barcode.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testTextSize()
|
||||
{
|
||||
$outp = $this -> runExample("text-size.php");
|
||||
$this -> outpTest($outp, "text-size.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testMarginsAndSpacing()
|
||||
{
|
||||
$outp = $this -> runExample("margins-and-spacing.php");
|
||||
$this -> outpTest($outp, "margins-and-spacing.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testPdf417Code()
|
||||
{
|
||||
$outp = $this -> runExample("pdf417-code.php");
|
||||
$this -> outpTest($outp, "pdf417-code.bin");
|
||||
}
|
||||
|
||||
public function testInterfaceCups()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/cups.php");
|
||||
}
|
||||
|
||||
public function testInterfaceEthernet()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/ethernet.php");
|
||||
}
|
||||
|
||||
public function testInterfaceLinuxUSB()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/linux-usb.php");
|
||||
}
|
||||
|
||||
public function testInterfaceWindowsUSB()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/windows-usb.php");
|
||||
}
|
||||
|
||||
public function testInterfaceSMB()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/smb.php");
|
||||
}
|
||||
|
||||
public function testInterfaceWindowsLPT()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/windows-lpt.php");
|
||||
}
|
||||
|
||||
private function runSyntaxCheck($fn)
|
||||
{
|
||||
$this -> runExample($fn, true);
|
||||
}
|
||||
|
||||
private function runExample($fn, $syntaxCheck = false)
|
||||
{
|
||||
// Change directory and check script
|
||||
chdir($this -> exampleDir);
|
||||
$this -> assertTrue(file_exists($fn), "Script $fn not found.");
|
||||
// Run command and save output
|
||||
$php = "php" . ($syntaxCheck ? " -l" : "");
|
||||
ob_start();
|
||||
passthru($php . " " . escapeshellarg($fn), $retval);
|
||||
$outp = ob_get_contents();
|
||||
ob_end_clean();
|
||||
// Check return value
|
||||
$this -> assertEquals(0, $retval, "Example $fn exited with status $retval");
|
||||
return $outp;
|
||||
}
|
||||
|
||||
protected function requireGraphicsLibrary()
|
||||
{
|
||||
if (!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) {
|
||||
$this -> markTestSkipped("This test requires a graphics library.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Mike42\Escpos\Devices\AuresCustomerDisplay;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
class AuresCustomerDisplayTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $printer;
|
||||
protected $outputConnector;
|
||||
|
||||
protected function setup()
|
||||
{
|
||||
/* Print to nowhere- for testing which inputs are accepted */
|
||||
$this -> outputConnector = new DummyPrintConnector();
|
||||
$profile = CapabilityProfile::load('OCD-300');
|
||||
$this -> printer = new AuresCustomerDisplay($this -> outputConnector, $profile);
|
||||
}
|
||||
|
||||
protected function checkOutput($expected = null)
|
||||
{
|
||||
/* Check those output strings */
|
||||
$outp = $this -> outputConnector -> getData();
|
||||
if ($expected === null) {
|
||||
echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n";
|
||||
}
|
||||
$this -> assertEquals($expected, $outp);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this -> outputConnector -> finalize();
|
||||
}
|
||||
|
||||
public function testInitializeOutput()
|
||||
{
|
||||
$this -> checkOutput("\x02\x05C1\x03\x1b@\x1bt\x00\x1f\x02");
|
||||
}
|
||||
|
||||
public function testselectTextScrollMode() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> selectTextScrollMode(AuresCustomerDisplay::TEXT_OVERWRITE);
|
||||
$this -> checkOutput("\x1f\x01");
|
||||
}
|
||||
|
||||
public function testClear() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> clear();
|
||||
$this -> checkOutput("\x0c");
|
||||
}
|
||||
|
||||
public function testShowFirmwareVersion() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> showFirmwareVersion();
|
||||
$this -> checkOutput("\x02\x05V\x01\x03");
|
||||
}
|
||||
|
||||
public function testSelfTest() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> selfTest();
|
||||
$this -> checkOutput("\x02\x05D\x08\x03");
|
||||
}
|
||||
|
||||
public function testShowLogo() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> showLogo();
|
||||
$this -> checkOutput("\x02\xfcU\xaaU\xaa");
|
||||
}
|
||||
|
||||
public function testTest() {
|
||||
$this -> outputConnector -> clear();
|
||||
// Handling of line-endings differs to regular printers, need to use \r\n
|
||||
$this -> printer -> text("Hello\nWorld\n");
|
||||
$this -> checkOutput("Hello\x0d\x0aWorld\x0d\x0a");
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
class CapabilityProfileTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testNames()
|
||||
{
|
||||
// Default is on the list
|
||||
$names = CapabilityProfile::getProfileNames();
|
||||
$this->assertFalse(array_search('simple', $names) === false);
|
||||
$this->assertFalse(array_search('default', $names) === false);
|
||||
$this->assertTrue(array_search('lalalalala', $names) === false);
|
||||
}
|
||||
|
||||
public function testLoadDefault()
|
||||
{
|
||||
// Just load the default profile and check it out
|
||||
$profile = CapabilityProfile::load('default');
|
||||
$this->assertEquals("default", $profile->getId());
|
||||
$this->assertEquals("Default", $profile->getName());
|
||||
$this->assertTrue($profile->getSupportsBarcodeB());
|
||||
$this->assertTrue($profile->getSupportsBitImageRaster());
|
||||
$this->assertTrue($profile->getSupportsGraphics());
|
||||
$this->assertTrue($profile->getSupportsQrCode());
|
||||
$this->assertTrue($profile->getSupportsPdf417Code());
|
||||
$this->assertFalse($profile->getSupportsStarCommands());
|
||||
$this->assertArrayHasKey('0', $profile->getCodePages());
|
||||
}
|
||||
|
||||
public function testCodePageCacheKey()
|
||||
{
|
||||
$default = CapabilityProfile::load('default');
|
||||
$simple = CapabilityProfile::load('simple');
|
||||
$this->assertNotEquals($default->getCodePageCacheKey(), $simple->getCodePageCacheKey());
|
||||
}
|
||||
|
||||
public function testBadProfileNameSuggestion()
|
||||
{
|
||||
$this->setExpectedException('\InvalidArgumentException', 'simple');
|
||||
$profile = CapabilityProfile::load('simpel');
|
||||
}
|
||||
|
||||
public function testBadFeatureNameSuggestion()
|
||||
{
|
||||
$this->setExpectedException('\InvalidArgumentException', 'graphics');
|
||||
$profile = CapabilityProfile::load('default');
|
||||
$profile->getFeature('graphicx');
|
||||
}
|
||||
|
||||
public function testSuggestions()
|
||||
{
|
||||
$input = "orangee";
|
||||
$choices = array("apple", "orange", "pear");
|
||||
$suggestions = CapabilityProfile::suggestNearest($input, $choices, 1);
|
||||
$this->assertEquals(1, count($suggestions));
|
||||
$this->assertEquals("orange", $suggestions[0]);
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\CodePage;
|
||||
|
||||
class CodePageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected function requiresIconv()
|
||||
{
|
||||
if (! extension_loaded('iconv')) {
|
||||
$this->markTestSkipped("Requires iconv");
|
||||
}
|
||||
}
|
||||
|
||||
public function testDataIconv()
|
||||
{
|
||||
// Set up CP437
|
||||
$this->requiresIconv();
|
||||
$cp = new CodePage("CP437", array(
|
||||
"name" => "CP437",
|
||||
"iconv" => "CP437"
|
||||
));
|
||||
$this->assertTrue($cp->isEncodable());
|
||||
$this->assertEquals($cp->getIconv(), "CP437");
|
||||
$this->assertEquals($cp->getName(), "CP437");
|
||||
$this->assertEquals($cp->getId(), "CP437");
|
||||
$this->assertEquals($cp->getNotes(), null);
|
||||
// Get data and see if it's right
|
||||
$data = $cp->getData();
|
||||
$expected = "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ";
|
||||
$this->assertEquals($expected, $data);
|
||||
}
|
||||
|
||||
public function testDataIconvBogus()
|
||||
{
|
||||
// No errors raised, you just get an empty list of supported characters if you try to compute a fake code page
|
||||
$this->requiresIconv();
|
||||
$cp = new CodePage("foo", array(
|
||||
"name" => "foo",
|
||||
"iconv" => "foo"
|
||||
));
|
||||
$this->assertTrue($cp->isEncodable());
|
||||
$this->assertEquals($cp->getIconv(), "foo");
|
||||
$this->assertEquals($cp->getName(), "foo");
|
||||
$this->assertEquals($cp->getId(), "foo");
|
||||
$this->assertEquals($cp->getNotes(), null);
|
||||
$data = $cp->getData();
|
||||
$expected = str_repeat(" ", 128);
|
||||
$this->assertEquals($expected, $data);
|
||||
// Do this twice (caching behaviour)
|
||||
$data = $cp->getData();
|
||||
$this->assertEquals($expected, $data);
|
||||
}
|
||||
|
||||
public function testDataCannotEncode()
|
||||
{
|
||||
$this->setExpectedException('\InvalidArgumentException');
|
||||
$cp = new CodePage("foo", array(
|
||||
"name" => "foo"
|
||||
));
|
||||
$this->assertFalse($cp->isEncodable());
|
||||
$cp->getData();
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
|
||||
|
||||
class CupsPrintConnectorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $connector;
|
||||
public function testPrinterExists()
|
||||
{
|
||||
$connector = $this->getMockConnector("FooPrinter", array("FooPrinter"));
|
||||
$connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' "));
|
||||
$connector->finalize();
|
||||
}
|
||||
public function testPrinterDoesntExist()
|
||||
{
|
||||
$this -> setExpectedException('BadMethodCallException');
|
||||
$connector = $this->getMockConnector("FooPrinter", array("OtherPrinter"));
|
||||
$connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' "));
|
||||
$connector->finalize();
|
||||
}
|
||||
public function testNoPrinter()
|
||||
{
|
||||
$this -> setExpectedException('BadMethodCallException');
|
||||
$connector = $this->getMockConnector("FooPrinter", array(""));
|
||||
}
|
||||
private function getMockConnector($path, array $printers)
|
||||
{
|
||||
$stub = $this->getMockBuilder('Mike42\Escpos\PrintConnectors\CupsPrintConnector')->setMethods(array (
|
||||
'getCmdOutput',
|
||||
'getLocalPrinters'
|
||||
))->disableOriginalConstructor()->getMock();
|
||||
$stub->method('getCmdOutput')->willReturn("");
|
||||
$stub->method('getLocalPrinters')->willReturn($printers);
|
||||
$stub->__construct($path);
|
||||
return $stub;
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class EscposImageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testImageMissingException()
|
||||
{
|
||||
$this -> setExpectedException('Exception');
|
||||
$img = EscposImage::load('not-a-real-file.png');
|
||||
}
|
||||
public function testImageNotSupportedException()
|
||||
{
|
||||
$this -> setExpectedException('InvalidArgumentException');
|
||||
$img = EscposImage::load('/dev/null', false, array());
|
||||
}
|
||||
}
|
||||
@ -1,192 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Example strings are pangrams using different character sets, and are
|
||||
* testing correct code-table switching.
|
||||
*
|
||||
* When printed, they should appear the same as in this source file.
|
||||
*
|
||||
* Many of these test strings are from:
|
||||
* - http://www.cl.cam.ac.uk/~mgk25/ucs/examples/quickbrown.txt
|
||||
* - http://clagnut.com/blog/2380/ (mirrored from the English Wikipedia)
|
||||
*/
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
|
||||
class EscposPrintBufferTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $buffer;
|
||||
protected $outputConnector;
|
||||
|
||||
protected function setup()
|
||||
{
|
||||
$this -> outputConnector = new DummyPrintConnector();
|
||||
$printer = new Printer($this -> outputConnector);
|
||||
$this -> buffer = $printer -> getPrintBuffer();
|
||||
}
|
||||
|
||||
protected function checkOutput($expected = null)
|
||||
{
|
||||
/* Check those output strings */
|
||||
$outp = $this -> outputConnector -> getData();
|
||||
if ($expected === null) {
|
||||
echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n";
|
||||
}
|
||||
$this -> assertEquals($expected, $outp);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this -> outputConnector -> finalize();
|
||||
}
|
||||
|
||||
public function testRawTextNonprintable()
|
||||
{
|
||||
$this -> buffer -> writeTextRaw("Test" . Printer::ESC . "v1\n");
|
||||
$this -> checkOutput("\x1b@Test?v1\x0a"); // ASCII ESC character is substituted for '?'
|
||||
}
|
||||
|
||||
public function testDanish()
|
||||
{
|
||||
$this -> buffer -> writeText("Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n");
|
||||
$this -> checkOutput("\x1b@Quizdeltagerne spiste jordb\x91r med fl\x1bt\x02\x9bde, mens cirkusklovnen Wolther spillede p\x86 xylofon.\x0a");
|
||||
}
|
||||
|
||||
public function testGerman()
|
||||
{
|
||||
$this -> buffer -> writeText("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n");
|
||||
$this -> checkOutput("\x1b@Falsches \x9aben von Xylophonmusik qu\x84lt jeden gr\x94\xe1eren Zwerg.\x0a");
|
||||
}
|
||||
|
||||
public function testGreek()
|
||||
{
|
||||
$this -> buffer -> writeText("Ξεσκεπάζω την ψυχοφθόρα βδελυγμία");
|
||||
$this -> checkOutput("\x1b@\x1bt\x0e\x8d\x9c\xa9\xa1\x9c\xa7\xe1\x9d\xe0 \xab\x9e\xa4 \xaf\xac\xae\xa6\xad\x9f\xe6\xa8\x98 \x99\x9b\x9c\xa2\xac\x9a\xa3\xe5\x98");
|
||||
}
|
||||
|
||||
public function testGreekWithDiacritics()
|
||||
{
|
||||
// This is a string which is known to be un-printable in ESC/POS (the grave-accented letters are not in any code page),
|
||||
// so we are checking the substitution '?' for unknown characters.
|
||||
$this -> buffer -> writeText("Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο.\n");
|
||||
$this -> checkOutput("\x1b@\xe2\xe0\x1bt\x0e\x9d\xe2\x9c\xaa \xa1\x98? \xa3\xac\xa8\xab\xa0?\xaa \x9b?\xa4 \x9f? \x99\xa8? \xa7\xa0? \xa9\xab? \xae\xa8\xac\xa9\x98\xad? \xa5\xe2\xad\xe0\xab\xa6.\x0a");
|
||||
}
|
||||
|
||||
public function testEnglish()
|
||||
{
|
||||
$this -> buffer -> writeText("The quick brown fox jumps over the lazy dog.\n");
|
||||
$this -> checkOutput("\x1b@The quick brown fox jumps over the lazy dog.\n");
|
||||
}
|
||||
|
||||
public function testSpanish()
|
||||
{
|
||||
// This one does not require changing code-pages at all, so characters are just converted from Unicode to CP437.
|
||||
$this -> buffer -> writeText("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n");
|
||||
$this -> checkOutput("\x1b@El ping\x81ino Wenceslao hizo kil\xa2metros bajo exhaustiva lluvia y fr\xa1o, a\xa4oraba a su querido cachorro.\x0a");
|
||||
}
|
||||
|
||||
public function testFrench()
|
||||
{
|
||||
$this -> buffer -> writeText("Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n");
|
||||
$this -> checkOutput("\x1b@Le c\x1bt\x10\x9cur d\xe9\xe7u mais l'\xe2me plut\xf4t na\xefve, Lou\xffs r\xeava de crapa\xfcter en cano\xeb au del\xe0 des \xeeles, pr\xe8s du m\xe4lstr\xf6m o\xf9 br\xfblent les nov\xe6.\x0a");
|
||||
}
|
||||
|
||||
public function testIrishGaelic()
|
||||
{
|
||||
// Note that some letters with diacritics cannot be printed for Irish Gaelic text, so text may need to be simplified.
|
||||
$this -> buffer -> writeText("D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n");
|
||||
$this -> checkOutput("\x1b@D'fhuascail \x1bt\x02\xd6osa, \xe9rmhac na h\xe0ighe Beannaithe, p\xa2r \x90ava agus \xb5dhaimh.\x0a");
|
||||
}
|
||||
|
||||
public function testHungarian()
|
||||
{
|
||||
$this -> buffer -> writeText("Árvíztűrő tükörfúrógép.\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x02\xb5rv\xa1zt\x1bt\x12\xfbr\x8b t\x81k\x94rf\xa3r\xa2g\x82p.\x0a");
|
||||
}
|
||||
|
||||
public function testIcelandic()
|
||||
{
|
||||
$this -> buffer -> writeText("Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa.");
|
||||
$this -> checkOutput("\x1b@K\x91mi n\x1bt\x02\xec \x94xi h\x82r ykist \xe7j\xa2fum n\xa3 b\x91\xd0i v\xa1l og \xa0drepa.");
|
||||
}
|
||||
|
||||
public function testJapaneseHiragana()
|
||||
{
|
||||
$this -> markTestIncomplete("Non-ASCII character sets not yet supported.");
|
||||
$this -> buffer -> writeText(implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n");
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testJapaneseKatakana()
|
||||
{
|
||||
$this -> markTestIncomplete("Non-ASCII character sets not yet supported.");
|
||||
$this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a");
|
||||
}
|
||||
|
||||
public function testJapaneseKataKanaHalfWidth()
|
||||
{
|
||||
$this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a");
|
||||
}
|
||||
|
||||
public function testLatvian()
|
||||
{
|
||||
$this -> buffer -> writeText("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n");
|
||||
$this -> checkOutput("\x1b@Gl\x1bt!\x83\xd8\xd5\xe9\xd7\xeca r\xd7\xe9\x8c\xd5i dz\x89rum\x83 \xd1iepj Baha koncertfl\x8c\x85e\xebu v\x83kus.\x0a");
|
||||
}
|
||||
|
||||
public function testPolish()
|
||||
{
|
||||
$this -> buffer -> writeText("Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n");
|
||||
$this -> checkOutput("\x1b@Pchn\x1bt\x12\xa5\x86 w t\xa9 \x88\xa2d\xab je\xbea lub o\x98m skrzy\xe4 fig.\x0a");
|
||||
}
|
||||
|
||||
public function testRussian()
|
||||
{
|
||||
$this -> buffer -> writeText("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x11\x82 \xe7\xa0\xe9\xa0\xe5 \xee\xa3\xa0 \xa6\xa8\xab \xa1\xeb \xe6\xa8\xe2\xe0\xe3\xe1? \x84\xa0, \xad\xae \xe4\xa0\xab\xec\xe8\xa8\xa2\xeb\xa9 \xed\xaa\xa7\xa5\xac\xaf\xab\xef\xe0!\x0a");
|
||||
}
|
||||
|
||||
public function testThai()
|
||||
{
|
||||
$this -> markTestIncomplete("Non-ASCII character sets not yet supported.");
|
||||
$this -> buffer -> writeText("นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n"); // Quotation from Wikipedia
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testTurkish()
|
||||
{
|
||||
$this -> buffer -> writeText("Pijamalı hasta, yağız şoföre çabucak güvendi.\n");
|
||||
$this -> checkOutput("\x1b@Pijamal\x1bt\x02\xd5 hasta, ya\x1bt\x0d\xa7\x8dz \x9fof\x94re \x87abucak g\x81vendi.\x0a");
|
||||
}
|
||||
|
||||
public function testArabic()
|
||||
{
|
||||
$this -> markTestIncomplete("Right-to-left text not yet supported.");
|
||||
$this -> buffer -> writeText("صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n"); // Quotation from Wikipedia
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testHebrew()
|
||||
{
|
||||
// RTL text is more complex than the above.
|
||||
$this -> markTestIncomplete("Right-to-left text not yet supported.");
|
||||
$this -> buffer -> writeText("דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n");
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testVietnamese() {
|
||||
$this -> buffer -> writeText("Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n");
|
||||
$this -> checkOutput("\x1b@Ti\x1bt\x1e\xd5ng Vi\xd6t, c\xdfn g\xe4i ti\xd5ng Vi\xd6t Nam hay Vi\xd6t ng\xf7, l\xb5 ng\xabn ng\xf7 c\xf1a ng\xad\xeai Vi\xd6t (ng\xad\xeai Kinh) v\xb5 l\xb5 ng\xabn ng\xf7 ch\xddnh th\xf8c t\xb9i Vi\xd6t Nam.\x0a");
|
||||
}
|
||||
|
||||
public function testWindowsLineEndings() {
|
||||
$this -> buffer -> writeText("Hello World!\r\n");
|
||||
$this -> checkOutput("\x1b@Hello World!\x0a");
|
||||
}
|
||||
|
||||
public function testWindowsLineEndingsRaw() {
|
||||
$this -> buffer -> writeTextRaw("Hello World!\r\n");
|
||||
$this -> checkOutput("\x1b@Hello World!\x0a");
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
class FilePrintConnectorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testTmpfile()
|
||||
{
|
||||
// Should attempt to send data to the local printer by writing to it
|
||||
$tmpfname = tempnam("/tmp", "php");
|
||||
$connector = new FilePrintConnector($tmpfname);
|
||||
$connector -> finalize();
|
||||
$connector -> finalize(); // Silently do nothing if printer already closed
|
||||
unlink($tmpfname);
|
||||
}
|
||||
|
||||
public function testReadAfterClose()
|
||||
{
|
||||
// Should attempt to send data to the local printer by writing to it
|
||||
$this -> setExpectedException('Exception');
|
||||
$tmpfname = tempnam("/tmp", "php");
|
||||
$connector = new FilePrintConnector($tmpfname);
|
||||
$connector -> finalize();
|
||||
$connector -> write("Test");
|
||||
unlink($tmpfname);
|
||||
}
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\GdEscposImage;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class GdEscposImageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Gd tests - Load tiny images and check how they are printed
|
||||
* These are skipped if you don't have imagick
|
||||
*/
|
||||
public function testGdBadFilename()
|
||||
{
|
||||
$this -> setExpectedException('Exception');
|
||||
$this -> loadAndCheckImg('not a real file.png', 1, 1, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdEmpty()
|
||||
{
|
||||
$this -> loadAndCheckImg(null, 0, 0, "", array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdBlack()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdBlackTransparent()
|
||||
{
|
||||
foreach (array('png', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdBlackWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an EscposImage with (optionally) certain libraries disabled and run a check.
|
||||
*/
|
||||
private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null)
|
||||
{
|
||||
if (!EscposImage::isGdLoaded()) {
|
||||
$this -> markTestSkipped("imagick plugin is required for this test");
|
||||
}
|
||||
$onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn"));
|
||||
// With optimisations
|
||||
$imgOptimised = new GdEscposImage($onDisk, true);
|
||||
$this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
// ... and without
|
||||
$imgUnoptimised = new GdEscposImage($onDisk, false);
|
||||
$this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image against known width, height, output.
|
||||
*/
|
||||
private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null)
|
||||
{
|
||||
$rasterFormatActual = $img -> toRasterFormat();
|
||||
$columnFormatActual = $img -> toColumnFormat();
|
||||
if ($rasterFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\"";
|
||||
}
|
||||
if ($columnFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\"";
|
||||
}
|
||||
$this -> assertTrue($img -> getHeight() == $height);
|
||||
$this -> assertTrue($img -> getWidth() == $width);
|
||||
$this -> assertTrue($rasterFormatExpected === $rasterFormatActual);
|
||||
$this -> assertTrue($columnFormatExpected === $columnFormatActual);
|
||||
}
|
||||
}
|
||||
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\ImagickEscposImage;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class ImagickEscposImageTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Imagick tests - Load tiny images and check how they are printed
|
||||
* These are skipped if you don't have imagick
|
||||
*/
|
||||
public function testImagickBadFilename()
|
||||
{
|
||||
$this -> setExpectedException('Exception');
|
||||
$this -> loadAndCheckImg('not a real file.png', 1, 1, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickEmpty()
|
||||
{
|
||||
$this -> loadAndCheckImg(null, 0, 0, "", array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlack()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlackTransparent()
|
||||
{
|
||||
foreach (array('png', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlackWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlackWhiteTall()
|
||||
{
|
||||
// We're very interested in correct column format chopping here at 8 pixels
|
||||
$this -> loadAndCheckImg('black_white_tall.png', 2, 16,
|
||||
"\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x00\x00\x00\x00\x00\x00\x00\x00", array("\xff\xff", "\x00\x00"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PDF test - load tiny PDF and check for well-formedness
|
||||
* These are also skipped if you don't have imagick
|
||||
* @medium
|
||||
*/
|
||||
public function testPdfAllPages()
|
||||
{
|
||||
$this -> loadAndCheckPdf('doc.pdf', 1, 1, array("\x00", "\x80"), array(array("\x00"), array("\x80")));
|
||||
}
|
||||
|
||||
public function testPdfBadFilename()
|
||||
{
|
||||
$this -> setExpectedException('Exception');
|
||||
$this -> loadAndCheckPdf('not a real file', 1, 1, array(), array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an EscposImage and run a check.
|
||||
*/
|
||||
private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null)
|
||||
{
|
||||
if (!EscposImage::isImagickLoaded()) {
|
||||
$this -> markTestSkipped("imagick plugin is required for this test");
|
||||
}
|
||||
$onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn"));
|
||||
// With optimisations
|
||||
$imgOptimised = new ImagickEscposImage($onDisk, true);
|
||||
$this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
// ... and without
|
||||
$imgUnoptimised = new ImagickEscposImage($onDisk, false);
|
||||
$this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as above, loading document and checking pages against some expected values.
|
||||
*/
|
||||
private function loadAndCheckPdf($fn, $width, $height, array $rasterFormat = null, array $columnFormat = null)
|
||||
{
|
||||
if (!EscposImage::isImagickLoaded()) {
|
||||
$this -> markTestSkipped("imagick plugin required for this test");
|
||||
}
|
||||
$pdfPages = ImagickEscposImage::loadPdf(dirname(__FILE__) . "/resources/$fn", $width);
|
||||
$this -> assertTrue(count($pdfPages) == count($rasterFormat), "Got back wrong number of pages");
|
||||
foreach ($pdfPages as $id => $img) {
|
||||
$this -> checkImg($img, $width, $height, $rasterFormat[$id], $columnFormat[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image against known width, height, output.
|
||||
*/
|
||||
private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null)
|
||||
{
|
||||
$rasterFormatActual = $img -> toRasterFormat();
|
||||
$columnFormatActual = $img -> toColumnFormat();
|
||||
if ($rasterFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\"";
|
||||
}
|
||||
if ($columnFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\"";
|
||||
}
|
||||
$this -> assertEquals($height , $img -> getHeight());
|
||||
$this -> assertEquals($width, $img -> getWidth());
|
||||
$this -> assertEquals($rasterFormatExpected, $rasterFormatActual, "Raster format did not match expected");
|
||||
$this -> assertEquals($columnFormatExpected, $columnFormatActual, "Column format did not match expected");
|
||||
}
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Test that the old API for capability profiles can still be used.
|
||||
*/
|
||||
use Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\Printer;
|
||||
|
||||
class LegacyCapabilityProfileTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $profiles;
|
||||
private $checklist;
|
||||
|
||||
function setup()
|
||||
{
|
||||
$this -> profiles = array(
|
||||
'Mike42\Escpos\CapabilityProfiles\DefaultCapabilityProfile',
|
||||
'Mike42\Escpos\CapabilityProfiles\EposTepCapabilityProfile',
|
||||
'Mike42\Escpos\CapabilityProfiles\SimpleCapabilityProfile',
|
||||
'Mike42\Escpos\CapabilityProfiles\StarCapabilityProfile',
|
||||
'Mike42\Escpos\CapabilityProfiles\P822DCapabilityProfile');
|
||||
$this -> checklist = array();
|
||||
foreach ($this -> profiles as $profile) {
|
||||
$this-> checklist[] = $profile::getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
function testSupportedCodePages()
|
||||
{
|
||||
foreach ($this -> checklist as $obj) {
|
||||
$check = $obj -> getCodePages();
|
||||
$this -> assertTrue(is_array($check) && isset($check[0]));
|
||||
foreach ($check as $num => $page) {
|
||||
$this -> assertTrue(is_numeric($num));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
function testSupportsBitImageRaster()
|
||||
{
|
||||
foreach ($this -> checklist as $obj) {
|
||||
$check = $obj -> getSupportsBitImageRaster();
|
||||
$this -> assertTrue(is_bool($check));
|
||||
}
|
||||
}
|
||||
|
||||
function testSupportsGraphics()
|
||||
{
|
||||
foreach ($this -> checklist as $obj) {
|
||||
$check = $obj -> getSupportsGraphics();
|
||||
$this -> assertTrue(is_bool($check));
|
||||
}
|
||||
}
|
||||
|
||||
function testSupportsQrCode()
|
||||
{
|
||||
foreach ($this -> checklist as $obj) {
|
||||
$check = $obj -> getSupportsQrCode();
|
||||
$this -> assertTrue(is_bool($check));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\UriPrintConnector;
|
||||
|
||||
class UriPrintConnectorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFile()
|
||||
{
|
||||
$filename = tempnam(sys_get_temp_dir(), "escpos-php-");
|
||||
// Make connector, write some data
|
||||
$connector = UriPrintConnector::get("file://" . $filename);
|
||||
$connector -> write("AAA");
|
||||
$connector -> finalize();
|
||||
$this -> assertEquals("AAA", file_get_contents($filename));
|
||||
$this -> assertEquals('Mike42\Escpos\PrintConnectors\FilePrintConnector', get_class($connector));
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
* @expectedExceptionMessage not finalized
|
||||
*/
|
||||
public function testSmb()
|
||||
{
|
||||
$connector = UriPrintConnector::get("smb://windows/printer");
|
||||
$this -> assertEquals('Mike42\Escpos\PrintConnectors\WindowsPrintConnector', get_class($connector));
|
||||
// We expect that this will throw an exception, we can't
|
||||
// realistically print to a real printer in this test though... :)
|
||||
$connector -> __destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Malformed connector URI
|
||||
*/
|
||||
public function testBadUri()
|
||||
{
|
||||
$connector = UriPrintConnector::get("foooooo");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Connection refused
|
||||
*/
|
||||
public function testNetwork()
|
||||
{
|
||||
// Port should be closed so we can catch an error and move on
|
||||
$connector = UriPrintConnector::get("tcp://localhost:45987/");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage URI sheme is not supported: ldap://
|
||||
*/
|
||||
public function testUnsupportedUri()
|
||||
{
|
||||
// Try to print to something silly
|
||||
$connector = UriPrintConnector::get("ldap://host:1234/");
|
||||
}
|
||||
}
|
||||
@ -1,304 +0,0 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
class WindowsPrintConnectorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $connector;
|
||||
|
||||
public function testLptWindows()
|
||||
{
|
||||
// Should attempt to send data to the local printer by writing to it
|
||||
$connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runWrite')
|
||||
-> with($this -> equalTo(''), $this -> equalTo("LPT1"));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testLptMac()
|
||||
{
|
||||
// Cannot print to local printer on Mac with this connector
|
||||
$this -> setExpectedException('BadMethodCallException');
|
||||
$connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_MAC);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testLptLinux()
|
||||
{
|
||||
// Cannot print to local printer on Linux with this connector
|
||||
$this -> setExpectedException('BadMethodCallException');
|
||||
$connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testComWindows()
|
||||
{
|
||||
// Simple file write
|
||||
$connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runWrite')
|
||||
-> with($this -> equalTo(''), $this -> equalTo("COM1"));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testComMac()
|
||||
{
|
||||
// Cannot print to local printer on Mac with this connector
|
||||
$this -> setExpectedException('BadMethodCallException');
|
||||
$connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_MAC);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testComLinux()
|
||||
{
|
||||
// Cannot print to local printer on Linux with this connector
|
||||
$this -> setExpectedException('BadMethodCallException');
|
||||
$connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testLocalShareWindows()
|
||||
{
|
||||
$connector = $this -> getMockConnector("Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> stringContains('\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindows()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindowsUsername()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\''));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindowsUsernameDomain()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:home\\bob\''));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindowsUsernamePassword()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\' \'secret\''));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterMac()
|
||||
{
|
||||
// Not implemented
|
||||
$this -> setExpectedException('Exception');
|
||||
$connector = $this -> getMockConnector("smb://Guest@example-pc/Printer", WindowsPrintConnector::PLATFORM_MAC);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinux()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' -c \'print -\' -N -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinuxUsername()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'bob\' -c \'print -\' -N -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinuxUsernameDomain()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'home\\bob\' -c \'print -\' -N -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinuxUsernamePassword()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' \'secret\' -U \'bob\' -c \'print -\' -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
private function getMockConnector($path, $platform)
|
||||
{
|
||||
$stub = $this -> getMockBuilder('Mike42\Escpos\PrintConnectors\WindowsPrintConnector')
|
||||
-> setMethods(array('runCopy', 'runCommand', 'getCurrentPlatform', 'runWrite'))
|
||||
-> disableOriginalConstructor()
|
||||
-> getMock();
|
||||
$stub -> method('runCommand')
|
||||
-> willReturn(0);
|
||||
$stub -> method('runCopy')
|
||||
-> willReturn(true);
|
||||
$stub -> method('runWrite')
|
||||
-> willReturn(true);
|
||||
$stub -> method('getCurrentPlatform')
|
||||
-> willReturn($platform);
|
||||
$stub -> __construct($path);
|
||||
return $stub;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for correct identification of bogus or non-supported Samba strings.
|
||||
*/
|
||||
public function testSambaRegex()
|
||||
{
|
||||
$good = array("smb://foo/bar",
|
||||
"smb://foo/bar baz",
|
||||
"smb://bob@foo/bar",
|
||||
"smb://bob:secret@foo/bar",
|
||||
"smb://foo-computer/FooPrinter",
|
||||
"smb://foo-computer/workgroup/FooPrinter",
|
||||
"smb://foo-computer/Foo-Printer",
|
||||
"smb://foo-computer/workgroup/Foo-Printer",
|
||||
"smb://foo-computer/Foo Printer",
|
||||
"smb://foo-computer.local/Foo Printer",
|
||||
"smb://127.0.0.1/abcd"
|
||||
);
|
||||
$bad = array("",
|
||||
"http://google.com",
|
||||
"smb:/foo/bar",
|
||||
"smb://",
|
||||
"smb:///bar",
|
||||
"smb://@foo/bar",
|
||||
"smb://bob:@foo/bar",
|
||||
"smb://:secret@foo/bar",
|
||||
"smb://foo/bar/baz/quux",
|
||||
"smb://foo-computer//FooPrinter");
|
||||
foreach ($good as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) == 1, "Windows samba regex should pass '$item'.");
|
||||
}
|
||||
foreach ($bad as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) != 1, "Windows samba regex should fail '$item'.");
|
||||
}
|
||||
}
|
||||
|
||||
public function testPrinterNameRegex()
|
||||
{
|
||||
$good = array("a",
|
||||
"ab",
|
||||
"a b",
|
||||
"a-b",
|
||||
"Abcd Efg-",
|
||||
"-a",
|
||||
"OK1"
|
||||
);
|
||||
$bad = array("",
|
||||
" ",
|
||||
"a ",
|
||||
" a",
|
||||
" a ",
|
||||
"a/B",
|
||||
"A:b"
|
||||
);
|
||||
foreach ($good as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) == 1, "Windows printer name regex should pass '$item'.");
|
||||
}
|
||||
foreach ($bad as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) != 1, "Windows printer name regex should fail '$item'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 65 B |
|
Before Width: | Height: | Size: 167 B |
|
Before Width: | Height: | Size: 138 B |
|
Before Width: | Height: | Size: 65 B |
|
Before Width: | Height: | Size: 175 B |
|
Before Width: | Height: | Size: 156 B |
|
Before Width: | Height: | Size: 162 B |
|
Before Width: | Height: | Size: 142 B |
|
Before Width: | Height: | Size: 72 B |
|
Before Width: | Height: | Size: 160 B |
|
Before Width: | Height: | Size: 239 B |
|
Before Width: | Height: | Size: 142 B |
|
Before Width: | Height: | Size: 72 B |
|
Before Width: | Height: | Size: 160 B |
|
Before Width: | Height: | Size: 239 B |
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
$im = new Imagick();
|
||||
try {
|
||||
$im -> readImage("doc.pdf[5]");
|
||||
$im -> destroy();
|
||||
} catch (ImagickException $e) {
|
||||
echo "Error: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
|
||||
$im = new Imagick();
|
||||
try {
|
||||
ob_start();
|
||||
@$im -> readImage("doc.pdf[5]");
|
||||
ob_end_clean();
|
||||
$im -> destroy();
|
||||
} catch (ImagickException $e) {
|
||||
echo "Error: " . $e -> getMessage() . "\n";
|
||||
}
|
||||