Skip to content

Commit

Permalink
Merge pull request #801 from mike42/development
Browse files Browse the repository at this point in the history
Changes for release v2.2
  • Loading branch information
mike42 authored Oct 5, 2019
2 parents 10b1230 + 21b1ad8 commit e5496cf
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Bematech LR2000E
- Birch PRP-085III
- Bixolon SRP-350III
- Bixolon SRP-350Plus
- Black Copper BC-85AC
- CHD TH-305N
- Citizen CBM1000-II
- Citizen CT-S310II
- Dapper-Geyi Q583P
- Daruma DR800
- DR-MP200 (manufacturer unknown)
- EPOS TEP 220M
- Elgin i9
- Epson EU-T332C
- Epson FX-890 (requires `feedForm()` to release paper).
- Epson TM-T20
Expand All @@ -98,9 +101,11 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Epson TM-U295 (requires `release()` to release slip).
- Epson TM-U590 and TM-U590P
- Equal (EQ-IT-001) POS-58
- Everycom EC-58
- Excelvan HOP-E200
- Excelvan HOP-E58
- Excelvan HOP-E801
- Gainscha GP-2120TF
- Gainscha GP-5890x (Also marketed as EC Line 5890x)
- Gainscha GP-U80300I (Also marketed as gprinter GP-U80300I)
- gprinter GP-U80160I
Expand All @@ -122,9 +127,13 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Rongta RP326US
- Rongta RP58-U
- Rongta RP80USE
- SAM4S GIANT-100DB
- Senor TP-100
- Sewoo SLK-TS400
- SEYPOS PRP-96
- SEYPOS PRP-300 (Also marketed as TYSSO PRP-300)
- SNBC BTP-R880NPIII
- Solux SX-TP-88300
- Sicar POS-80
- Silicon SP-201 / RP80USE
- SPRT SP-POS88V
Expand All @@ -133,6 +142,7 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Star TSP100III FuturePRNT
- Star TSP-650
- Star TUP-592
- TVS RP45 Shoppe
- Venus V248T
- Xeumior SM-8330
- Xprinter F-900
Expand All @@ -146,6 +156,7 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Zjiang ZJ-5870
- Zjiang ZJ-5890 (Also sold as POS-5890 by many vendors; ZJ-5890K, ZJ-5890T also work).
- Zjiang ZJ-8220 (Also marketed as Excelvan ZJ-8220)
- Zjiang ZJ-8250

If you use any other printer with this code, please [let us know](https://github.com/mike42/escpos-php/issues/new) so that it can be added to the list.

Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Each example prints to standard output, so either edit the print connector, or r
- `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”
76 changes: 76 additions & 0 deletions example/rawbt-receipt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!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>
145 changes: 145 additions & 0 deletions example/rawbt-receipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?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();
}

}
Binary file added example/resources/rawbtlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions src/Mike42/Escpos/PrintConnectors/RawbtPrintConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* This file is part of escpos-php: PHP receipt printer library for use with
* ESC/POS-compatible thermal and impact printers.
*
* Copyright (c) 2014-18 Michael Billington < [email protected] >,
* incorporating modifications by others. See CONTRIBUTORS.md for a full list.
*
* This software is distributed under the terms of the MIT license. See LICENSE.md
* for details.
*/

namespace Mike42\Escpos\PrintConnectors;

/**
* Print connector for android RawBT application
* https://play.google.com/store/apps/details?id=ru.a402d.rawbtprinter
*/
final class RawbtPrintConnector implements PrintConnector
{
/**
* @var array $buffer
* Buffer of accumilated data.
*/
private $buffer;

/**
* @var string data which the printer will provide on next read
*/
private $readData;

/**
* Create new print connector
*/
public function __construct()
{
ob_start();
$this->buffer = [];
}

public function clear()
{
$this->buffer = [];
}

public function __destruct()
{
if ($this->buffer !== null) {
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE);
}
}

public function finalize()
{
ob_end_clean();
echo "intent:base64," . base64_encode($this->getData()) . "#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;";
$this->buffer = null;
}

/**
* @return string Get the accumulated data that has been sent to this buffer.
*/
public function getData()
{
return implode($this->buffer);
}

/**
* {@inheritDoc}
* @see PrintConnector::read()
*/
public function read($len)
{
return $len >= strlen($this->readData) ? $this->readData : substr($this->readData, 0, $len);
}

public function write($data)
{
$this->buffer[] = $data;
}
}

0 comments on commit e5496cf

Please sign in to comment.