Skip to content
Snippets Groups Projects
Commit 55dfa485 authored by Frédéric France's avatar Frédéric France
Browse files

Install lib with composer

parent 8a765bf5
No related branches found
No related tags found
No related merge requests found
Showing
with 4 additions and 5251 deletions
......@@ -433,8 +433,8 @@ $object->vendor_firstname = 'Jim';
$object->vendor_lastname = 'Big';
$object->barcode = '3700123862396';
$printer->sendToPrinter($object, 1, 16);
setEventMessages($printer->error, $printer->errors, 'errors');
//$printer->sendToPrinter($object, 1, 16);
//setEventMessages($printer->error, $printer->errors, 'errors');
llxFooter();
......
......@@ -92,7 +92,7 @@
*
*/
require_once DOL_DOCUMENT_ROOT .'/includes/escpos/Escpos.php';
require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/Escpos.php';
/**
......
# Eclipse files
.settings/*
.project
.buildpath
# doxygen files
doc/html
doc/latex
doc/doxygen_sqlite3.db
# composer files
vendor/
This diff is collapsed.
escpos-php, a Thermal receipt printer library, for use with
ESC/POS compatible printers.
Copyright (c) 2014-15 Michael Billington <michael.billington@gmail.com>,
incorporating modifications by:
- Roni Saha <roni.cse@gmail.com>
- Gergely Radics <gerifield@ustream.tv>
- Warren Doyle <w.doyle@fuelled.co>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
ESC/POS Print Driver for PHP
============================
This project implements a subset of Epson's ESC/POS protocol for thermal receipt printers. It allows you to generate and print receipts with basic formatting, cutting, and barcodes on a compatible printer.
The library was developed to add drop-in support for receipt printing to any PHP app, including web-based point-of-sale (POS) applications.
Basic usage
-----------
A "hello world" receipt can be generated easily (Call this `hello-world.php`):
```php
<?php
require_once(dirname(__FILE__) . "/Escpos.php");
$printer = new Escpos();
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();
```
This would be printed as:
```
# Networked printer
php hello-world.php | nc 10.x.x.x. 9100
# Local printer
php hello-world.php > /dev/...
# Windows local printer
php hello-world.php > foo.txt
net use LPT1 \\server\printer
copy foo.txt LPT1
del foo.txt
```
From your web app, you could pass the output directly to a socket if your printer is networked:
```php
<?php
require_once(dirname(__FILE__) . "/Escpos.php");
$connector = new NetworkPrintConnector("10.x.x.x", 9100);
$printer = new Escpos($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();
```
Or to a local printer:
```php
<?php
require_once(dirname(__FILE__) . "/Escpos.php");
$connector = new FilePrintConnector("/dev/ttyS0");
$printer = new Escpos($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();
```
### Basic workflow
The library should be initialised with a PrintConnector, which will pass on the data to your printer.
Use the table under "Compatibility", or the examples below to choose the appropriate connector for your
platform & interface. If no connector is specified, then standard output is used.
When you have finished using the print object, call `close()` to finalize any data transfers.
### Tips & examples
On Linux, your printer device file will be somewhere like `/dev/lp0` (parallel), `/dev/usb/lp1` (USB), `/dev/ttyUSB0` (USB-Serial), `/dev/ttyS0` (serial).
On Windows, the device files will be along the lines of `LPT1` (parallel) or `COM1` (serial). Use the `WindowsPrintConnector` to tap into system printing on Windows (eg. [Windows USB](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php), [SMB](https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php) or [Windows LPT](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php)) - this submits print jobs via a queue rather than communicating directly with the printer.
A complete real-world receipt can be found in the code of [Auth](https://github.com/mike42/Auth) in [ReceiptPrinter.php](https://github.com/mike42/Auth/blob/master/lib/misc/ReceiptPrinter.php). It includes justification, boldness, and a barcode.
Other examples are located in the [example/](https://github.com/mike42/escpos-php/blob/master/example/) directory.
Compatibility
-------------
### Interfaces and operating systems
This driver is known to work with the following OS/interface combinations:
<table>
<tr>
<th>&nbsp;</th>
<th>Linux</th>
<th>Mac</th>
<th>Windows</th>
</tr>
<tr>
<th>Ethernet</th>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
</tr>
<tr>
<th>USB</th>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/linux-usb.php">Yes</a></td>
<td>Not tested</td>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php">Yes</a></td>
</tr>
<tr>
<th>USB-serial</th>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<th>Serial</th>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<th>Parallel</th>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php">Yes</a></td>
<td>Not tested</td>
<td>Yes</td>
</tr>
<tr>
<th>SMB shared</th>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php">Yes</a></td>
<td>No</td>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php">Yes</a></td>
</tr>
</table>
### Printers
Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with:
- EPOS TEP 220M
- Epson TM-T88III
- Epson TM-T88IV
- Epson TM-T70
- Epson TM-T82II
- Epson TM-T20
- Epson TM-T70II
- Epson TM-U220
- Epson FX-890 (requires `feedForm()` to release paper).
- Okipos 80 Plus III
- P-822D
- SEYPOS PRP-300 (Also marketed as TYSSO PRP-300)
- Star TSP-650
- Star TUP-592
- Xprinter XP-Q800
- Zijang NT-58H
- Zijang ZJ-5870
- Zijang ZJ-5890T (Marketed as POS 5890T)
If you use any other printer with this code, please let me know so I can add it to the list.
Available methods
-----------------
### __construct(PrintConnector $connector, AbstractCapabilityProfile $profile)
Construct new print object.
Parameters:
- `PrintConnector $connector`: The PrintConnector to send data to. If not set, output is sent to standard output.
- `AbstractCapabilityProfile $profile` Supported features of this printer. If not set, the DefaultCapabilityProfile will be used, which is suitable for Epson printers.
See [example/interface/]("https://github.com/mike42/escpos-php/tree/master/example/interface/) for ways to open connections for different platforms and interfaces.
### barcode($content, $type)
Print a barcode.
Parameters:
- `string $content`: The information to encode.
- `int $type`: The barcode standard to output. If not specified, `Escpos::BARCODE_CODE39` will be used.
Currently supported barcode standards are (depending on your printer):
- `BARCODE_UPCA`
- `BARCODE_UPCE`
- `BARCODE_JAN13`
- `BARCODE_JAN8`
- `BARCODE_CODE39`
- `BARCODE_ITF`
- `BARCODE_CODABAR`
Note that some barcode standards can only encode numbers, so attempting to print non-numeric codes with them may result in strange behaviour.
### bitImage(EscposImage $image, $size)
See [graphics()](#graphicsescposimage-image-size) below.
### cut($mode, $lines)
Cut the paper.
Parameters:
- `int $mode`: Cut mode, either `Escpos::CUT_FULL` or `Escpos::CUT_PARTIAL`. If not specified, `Escpos::CUT_FULL` will be used.
- `int $lines`: Number of lines to feed before cutting. If not specified, 3 will be used.
### feed($lines)
Print and feed line / Print and feed n lines.
Parameters:
- `int $lines`: Number of lines to feed
### feedForm()
Some printers require a form feed to release the paper. On most printers, this command is only useful in page mode, which is not implemented in this driver.
### feedReverse($lines)
Print and reverse feed n lines.
Parameters:
- `int $lines`: number of lines to feed. If not specified, 1 line will be fed.
### graphics(EscposImage $image, $size)
Print an image to the printer.
Parameters:
- `EscposImage $img`: The image to print.
- `int $size`: Output size modifier for the image.
Size modifiers are:
- `IMG_DEFAULT` (leave image at original size)
- `IMG_DOUBLE_WIDTH`
- `IMG_DOUBLE_HEIGHT`
A minimal example:
```php
<?php
$img = new EscposImage("logo.png");
$printer -> graphics($img);
```
See the [example/](https://github.com/mike42/escpos-php/blob/master/example/) folder for detailed examples.
The function [bitImage()](#bitimageescposimage-image-size) takes the same parameters, and can be used if your printer doesn't support the newer graphics commands.
### initialize()
Initialize printer. This resets formatting back to the defaults.
### pulse($pin, $on_ms, $off_ms)
Generate a pulse, for opening a cash drawer if one is connected. The default settings (0, 120, 240) should open an Epson drawer.
Parameters:
- `int $pin`: 0 or 1, for pin 2 or pin 5 kick-out connector respectively.
- `int $on_ms`: pulse ON time, in milliseconds.
- `int $off_ms`: pulse OFF time, in milliseconds.
### qrCode($content, $ec, $size, $model)
Print the given data as a QR code on the printer.
- `string $content`: The content of the code. Numeric data will be more efficiently compacted.
- `int $ec` Error-correction level to use. One of `Escpos::QR_ECLEVEL_L` (default), `Escpos::QR_ECLEVEL_M`, `Escpos::QR_ECLEVEL_Q` or `Escpos::QR_ECLEVEL_H`. Higher error correction results in a less compact code.
- `int $size`: Pixel size to use. Must be 1-16 (default 3)
- `int $model`: QR code model to use. Must be one of `Escpos::QR_MODEL_1`, `Escpos::QR_MODEL_2` (default) or `Escpos::QR_MICRO` (not supported by all printers).
### selectPrintMode($mode)
Select print mode(s).
Parameters:
- `int $mode`: The mode to use. Default is `Escpos::MODE_FONT_A`, with no special formatting. This has a similar effect to running `initialize()`.
Several MODE_* constants can be OR'd together passed to this function's `$mode` argument. The valid modes are:
- `MODE_FONT_A`
- `MODE_FONT_B`
- `MODE_EMPHASIZED`
- `MODE_DOUBLE_HEIGHT`
- `MODE_DOUBLE_WIDTH`
- `MODE_UNDERLINE`
### setBarcodeHeight($height)
Set barcode height.
Parameters:
- `int $height`: Height in dots. If not specified, 8 will be used.
### setDoubleStrike($on)
Turn double-strike mode on/off.
Parameters:
- `boolean $on`: true for double strike, false for no double strike.
### setEmphasis($on)
Turn emphasized mode on/off.
Parameters:
- `boolean $on`: true for emphasis, false for no emphasis.
### setFont($font)
Select font. Most printers have two fonts (Fonts A and B), and some have a third (Font C).
Parameters:
- `int $font`: The font to use. Must be either `Escpos::FONT_A`, `Escpos::FONT_B`, or `Escpos::FONT_C`.
### setJustification($justification)
Select justification.
Parameters:
- `int $justification`: One of `Escpos::JUSTIFY_LEFT`, `Escpos::JUSTIFY_CENTER`, or `Escpos::JUSTIFY_RIGHT`.
### setReverseColors($on)
Set black/white reverse mode on or off. In this mode, text is printed white on a black background.
Parameters:
- `boolean $on`: True to enable, false to disable.
### setTextSize($widthMultiplier, $heightMultiplier)
Set the size of text, as a multiple of the normal size.
Parameters:
- `int $widthMultiplier`: Multiple of the regular height to use (range 1 - 8).
- `int $heightMultiplier`: Multiple of the regular height to use (range 1 - 8).
### setUnderline($underline)
Set underline for printed text.
Parameters:
- `int $underline`: Either `true`/`false`, or one of `Escpos::UNDERLINE_NONE`, `Escpos::UNDERLINE_SINGLE` or `Escpos::UNDERLINE_DOUBLE`. Defaults to `Escpos::UNDERLINE_SINGLE`.
### text($str)
Add text to the buffer. Text should either be followed by a line-break, or `feed()` should be called after this.
Parameters:
- `string $str`: The string to print.
Further notes
-------------
Posts I've written up for people who are learning how to use receipt printers:
* [What is ESC/POS, and how do I use it?](http://mike.bitrevision.com/blog/what-is-escpos-and-how-do-i-use-it), which documents the output of test.php.
* [Setting up an Epson receipt printer](http://mike.bitrevision.com/blog/2014-20-26-setting-up-an-epson-receipt-printer)
* [Getting a USB receipt printer working on Linux](http://mike.bitrevision.com/blog/2015-03-getting-a-usb-receipt-printer-working-on-linux)
Other versions
--------------
Some forks of this project have been developed by others for specific use cases. Improvements from the following projects have been incorporated into escpos-php:
- [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP)
- [ronisaha/php-esc-pos](https://github.com/ronisaha/php-esc-pos)
Vendor documentation
--------------------
Epson notes that not all of its printers support all ESC/POS features, and includes a table in their documentation:
* [FAQ about ESC/POS from Epson](http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf)
Note that many printers produced by other vendors use the same standard, and are compatible by varying degrees.
{
"name": "mike42/escpos-php",
"type": "library",
"description": "Thermal receipt printer library, for use with ESC/POS compatible printers",
"homepage": "https://github.com/mike42/escpos-php",
"keywords": ["receipt", "print", "escpos", "ESC-POS", "driver"],
"license": "MIT",
"authors": [
{
"name": "Michael Billington",
"email": "michael.billington@gmail.com"
},
{
"name": "Roni Saha",
"email": "roni.cse@gmail.com"
},
{
"name": "Gergely Radics",
"email": "gerifield@ustream.tv"
},
{
"name": "Warren Doyle",
"email": "w.doyle@fuelled.co"
},
{
"name": "vharo",
"email": "vharo@geepok.com"
}
],
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.5.*"
}
}
This diff is collapsed.
html: ../Escpos.php escpos.conf
doxygen escpos.conf
latex: html
# Do nothing
clean:
rm --preserve-root -Rf html latex doxygen_sqlite3.db
This diff is collapsed.
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)
<?php
require_once (dirname ( __FILE__ ) . "/../Escpos.php");
$printer = new Escpos ();
$printer->setBarcodeHeight ( 40 );
/* Text position */
$printer->selectPrintMode ( Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH );
$printer->text ( "Text position\n" );
$printer->selectPrintMode ();
$hri = array (
Escpos::BARCODE_TEXT_NONE => "No text",
Escpos::BARCODE_TEXT_ABOVE => "Above",
Escpos::BARCODE_TEXT_BELOW => "Below",
Escpos::BARCODE_TEXT_ABOVE | Escpos::BARCODE_TEXT_BELOW => "Both"
);
foreach ( $hri as $position => $caption ) {
$printer->text ( $caption . "\n" );
$printer->setBarcodeTextPosition ( $position );
$printer->barcode ( "012345678901", Escpos::BARCODE_JAN13 );
$printer->feed ();
}
/* Barcode types */
$standards = array (
Escpos::BARCODE_UPCA => array (
"title" => "UPC-A",
"caption" => "Fixed-length numeric product barcodes.",
"example" => array (
array (
"caption" => "12 char numeric including (wrong) check digit.",
"content" => "012345678901"
),
array (
"caption" => "Send 11 chars to add check digit automatically.",
"content" => "01234567890"
)
)
),
Escpos::BARCODE_UPCE => array (
"title" => "UPC-E",
"caption" => "Fixed-length numeric compact product barcodes.",
"example" => array (
array (
"caption" => "6 char numeric - auto check digit & NSC",
"content" => "123456"
),
array (
"caption" => "7 char numeric - auto check digit",
"content" => "0123456"
),
array (
"caption" => "8 char numeric",
"content" => "01234567"
),
array (
"caption" => "11 char numeric - auto check digit",
"content" => "01234567890"
),
array (
"caption" => "12 char numeric including (wrong) check digit",
"content" => "012345678901"
)
)
),
Escpos::BARCODE_JAN13 => array (
"title" => "JAN13/EAN13",
"caption" => "Fixed-length numeric barcodes.",
"example" => array (
array (
"caption" => "12 char numeric - auto check digit",
"content" => "012345678901"
),
array (
"caption" => "13 char numeric including (wrong) check digit",
"content" => "0123456789012"
)
)
),
Escpos::BARCODE_JAN8 => array (
"title" => "JAN8/EAN8",
"caption" => "Fixed-length numeric barcodes.",
"example" => array (
array (
"caption" => "7 char numeric - auto check digit",
"content" => "0123456"
),
array (
"caption" => "8 char numeric including (wrong) check digit",
"content" => "01234567"
)
)
),
Escpos::BARCODE_CODE39 => array (
"title" => "Code39",
"caption" => "Variable length alphanumeric w/ some special chars.",
"example" => array (
array (
"caption" => "Text, numbers, spaces",
"content" => "ABC 012"
),
array (
"caption" => "Special characters",
"content" => "$%+-./"
),
array (
"caption" => "Extra char (*) Used as start/stop",
"content" => "*TEXT*"
)
)
),
Escpos::BARCODE_ITF => array (
"title" => "ITF",
"caption" => "Variable length numeric w/even number of digits,\nas they are encoded in pairs.",
"example" => array (
array (
"caption" => "Numeric- even number of digits",
"content" => "0123456789"
)
)
),
Escpos::BARCODE_CODABAR => array (
"title" => "Codabar",
"caption" => "Varaible length numeric with some allowable\nextra characters. ABCD/abcd must be used as\nstart/stop characters (one at the start, one\nat the end) to distinguish between barcode\napplications.",
"example" => array (
array (
"caption" => "Numeric w/ A A start/stop. ",
"content" => "A012345A"
),
array (
"caption" => "Extra allowable characters",
"content" => "A012$+-./:A"
)
)
),
Escpos::BARCODE_CODE93 => array (
"title" => "Code93",
"caption" => "Variable length- any ASCII is available",
"example" => array (
array (
"caption" => "Text",
"content" => "012abcd"
)
)
),
Escpos::BARCODE_CODE128 => array (
"title" => "Code128",
"caption" => "Variable length- any ASCII is available",
"example" => array (
array (
"caption" => "Code set A uppercase & symbols",
"content" => "{A" . "012ABCD"
),
array (
"caption" => "Code set B general text",
"content" => "{B" . "012ABCDabcd"
),
array (
"caption" => "Code set C compact numbers\n Sending chr(21) chr(32) chr(43)",
"content" => "{C" . chr ( 21 ) . chr ( 32 ) . chr ( 43 )
)
)
)
);
$printer->setBarcodeTextPosition ( Escpos::BARCODE_TEXT_BELOW );
foreach ( $standards as $type => $standard ) {
$printer->selectPrintMode ( Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH );
$printer->text ( $standard ["title"] . "\n" );
$printer->selectPrintMode ();
$printer->text ( $standard ["caption"] . "\n\n" );
foreach ( $standard ["example"] as $id => $barcode ) {
$printer->setEmphasis ( true );
$printer->text ( $barcode ["caption"] . "\n" );
$printer->setEmphasis ( false );
$printer->text ( "Content: " . $barcode ["content"] . "\n" );
$printer->barcode ( $barcode ["content"], $type );
$printer->feed ();
}
}
$printer->cut ();
$printer->close ();
<?php
/* Example print-outs using the older bit image print command */
require_once(dirname(__FILE__) . "/../Escpos.php");
$printer = new Escpos();
try {
$tux = new EscposImage("resources/tux.png");
$printer -> text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n");
$printer -> bitImage($tux);
$printer -> text("Regular Tux (bit image).\n");
$printer -> feed();
$printer -> bitImage($tux, Escpos::IMG_DOUBLE_WIDTH);
$printer -> text("Wide Tux (bit image).\n");
$printer -> feed();
$printer -> bitImage($tux, Escpos::IMG_DOUBLE_HEIGHT);
$printer -> text("Tall Tux (bit image).\n");
$printer -> feed();
$printer -> bitImage($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
$printer -> text("Large Tux in correct proportion (bit image).\n");
} catch(Exception $e) {
/* Images not supported on your PHP, or image file not found */
$printer -> text($e -> getMessage() . "\n");
}
$printer -> cut();
$printer -> close();
?>
<?php
/* Change to the correct path if you copy this example! */
require_once(dirname(__FILE__) . "/../Escpos.php");
/**
* This example builds on character-encodings.php, also providing an image-based rendering.
* This is quite slow, since a) the buffers are changed dozens of
* times in the example, and b) It involves sending very wide images, which printers don't like!
*
* There are currently no test cases around the image printing, since it is an experimental feature.
*
* It does, however, illustrate the way that more encodings are available when image output is used.
*/
include(dirname(__FILE__) . '/resources/character-encoding-test-strings.inc');
try {
// Enter connector and capability profile
$connector = new FilePrintConnector("php://stdout");
$profile = DefaultCapabilityProfile::getInstance();
$buffers = array(new EscposPrintBuffer(), new ImagePrintBuffer());
/* Print a series of receipts containing i18n example strings */
$printer = new Escpos($connector, $profile);
$printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
$printer -> text("Implemented languages\n");
$printer -> selectPrintMode();
foreach($inputsOk as $label => $str) {
$printer -> setEmphasis(true);
$printer -> text($label . ":\n");
$printer -> setEmphasis(false);
foreach($buffers as $buffer) {
$printer -> setPrintBuffer($buffer);
$printer -> text($str);
}
$printer -> setPrintBuffer($buffers[0]);
}
$printer -> feed();
$printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
$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";
}
<?php
/* Change to the correct path if you copy this example! */
require_once(dirname(__FILE__) . "/../Escpos.php");
/**
* 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 = DefaultCapabilityProfile::getInstance();
/* Print a series of receipts containing i18n example strings */
$printer = new Escpos($connector, $profile);
$printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
$printer -> text("Implemented languages\n");
$printer -> selectPrintMode();
foreach($inputsOk as $label => $str) {
$printer -> setEmphasis(true);
$printer -> text($label . ":\n");
$printer -> setEmphasis(false);
$printer -> text($str);
}
$printer -> feed();
$printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::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";
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment