# ESC/POS Print Driver for PHP
[![Build Status](https://travis-ci.org/mike42/escpos-php.svg?branch=master)](https://travis-ci.org/mike42/escpos-php) [![Latest Stable Version](https://poser.pugx.org/mike42/escpos-php/v/stable)](https://packagist.org/packages/mike42/escpos-php)
[![Total Downloads](https://poser.pugx.org/mike42/escpos-php/downloads)](https://packagist.org/packages/mike42/escpos-php)
[![License](https://poser.pugx.org/mike42/escpos-php/license)](https://packagist.org/packages/mike42/escpos-php)
[![Coverage Status](https://coveralls.io/repos/github/mike42/escpos-php/badge.svg?branch=development)](https://coveralls.io/github/mike42/escpos-php?branch=development)
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.
## Compatibility
### Interfaces and operating systems
This driver is known to work with the following OS/interface combinations:
<table>
<tr>
<th> </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>
<tr>
<th>CUPS hosted</th>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/cups.php">Yes</a></td>
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/cups.php">Yes</a></td>
<td>No</td>
</tr>
</table>
### Printers
Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with:
- 3nStar RPT-008
- Approx APPPOS80AM
- AURES ODP-333
- AURES ODP-500
- Bematech-4200-TH
- Bematech LR2000E
- Birch PRP-085III
- Bixolon SRP-350III
- Black Copper BC-85AC
- Citizen CBM1000-II
- Citizen CT-S310II
- Dapper-Geyi Q583P
- Daruma DR800
- DR-MP200 (manufacturer unknown)
- EPOS TEP 220M
- Epson EU-T332C
- Epson FX-890 (requires `feedForm()` to release paper).
- Epson TM-T20
- Epson TM-T20II
- Epson TM-T70
- Epson TM-T70II
- Epson TM-T81
- Epson TM-T82II
- Epson TM-T88II
- Epson TM-T88III
- Epson TM-T88IV
- Epson TM-T88V
- Epson TM-U220
- Epson TM-U295 (requires `release()` to release slip).
- Epson TM-U590 and TM-U590P
- Equal (EQ-IT-001) POS-58
- Excelvan HOP-E200
- Excelvan HOP-E58
- Excelvan HOP-E801
- Gainscha GP-5890x (Also marketed as EC Line 5890x)
- Gainscha GP-U80300I (Also marketed as gprinter GP-U80300I)
- gprinter GP-U80160I
- HOIN HOP-H58
- Ithaca iTherm 28
- Hasar HTP 250
- Metapace T-1
- Metapace T-25
- Nexa PX700
- Nyear NP100
- OKI RT322
- OKI 80 Plus III
- Orient BTP-R580
- P-822D
- P85A-401 (make unknown)
- Partner Tech RP320
- POSLIGNE ODP200H-III-G
- QPOS Q58M
- Rongta RP326US
- Rongta RP58-U
- Rongta RP80USE
- Senor TP-100
- Sewoo SLK-TS400
- SEYPOS PRP-300 (Also marketed as TYSSO PRP-300)
- Sicar POS-80
- Silicon SP-201 / RP80USE
- SPRT SP-POS88V
- Star BSC10
- Star TSP100 ECO
- Star TSP100III FuturePRNT
- Star TSP-650
- Star TUP-592
- Venus V248T
- Xeumior SM-8330
- Xprinter F-900
- Xprinter XP-365B
- Xprinter XP-58 Series
- Xprinter XP-80C
- Xprinter XP-90
- XPrinter XP-Q20011
- Xprinter XP-Q800
- Zjiang NT-58H
- 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)
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.
## Basic usage
### Include the library
#### Composer
If you are using composer, then add `mike42/escpos-php` as a dependency:
```bash
composer require mike42/escpos-php
```
In this case, you would include composer's auto-loader at the top of your source files:
```php
<?php
require __DIR__ . '/vendor/autoload.php';
```
#### Manually
If you don't have composer available, then simply download the code and include `autoload.php`:
```bash
git clone https://github.com/mike42/escpos-php vendor/mike42/escpos-php
```
```php
<?php
require __DIR__ . '/vendor/mike42/escpos-php/autoload.php';
```
#### Requirements
To maintain compatibility with as many systems as possible, this driver has few
hard dependencies:
- PHP 5.4 or above.
- `mbstring` extension, since the driver accepts UTF-8 encoding.
It is also suggested that you install either `imagick` or `gd`, so that you can
print images.
A number of optional packages can be added to enable more specific features. These
are described in the "suggest" section of [composer.json](https://github.com/mike42/escpos-php/tree/master/composer.json).
### The 'Hello World' receipt
To make use of this driver, your server (where PHP is installed) must be able to communicate with your printer. Start by generating a simple receipt and sending it to your printer using the command-line.
```php
<?php
/* Call this file 'hello-world.php' */
require __DIR__ . '/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();
```
Some examples are below for common interfaces.
Communicate with a printer with an Ethernet interface using `netcat`:
```bash
php hello-world.php | nc 10.x.x.x. 9100
```
A USB local printer connected with `usblp` on Linux has a device file (Includes USB-parallel interfaces):
```bash
php hello-world.php > /dev/usb/lp0
```
A computer installed into the local `cups` server is accessed through `lp` or `lpr`:
```bash
php hello-world.php > foo.txt
lpr -o raw -H localhost -P printer foo.txt
```
A local or networked printer on a Windows computer is mapped in to a file, and generally requires you to share the printer first:
```
php hello-world.php > foo.txt
net use LPT1 \\server\printer
copy foo.txt LPT1
del foo.txt
```
If you have troubles at this point, then you should consult your OS and printer system documentation to try to find a working print command.
### Using a PrintConnector
To print receipts from PHP, use the most applicable [PrintConnector](https://github.com/mike42/escpos-php/tree/master/src/Mike42/Escpos/PrintConnectors) for your setup. The connector simply provides the plumbing to get data to the printer.
For example, a `NetworkPrintConnector` accepts an IP address and port:
```php
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;
$connector = new NetworkPrintConnector("10.x.x.x", 9100);
$printer = new Printer($connector);
try {
// ... Print stuff
} finally {
$printer -> close();
}
```
While a serial printer might use:
```php
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
$connector = new FilePrintConnector("/dev/ttyS0");
没有合适的资源?快使用搜索试试~ 我知道了~
php实现网络打印机打印
共143个文件
php:78个
bin:11个
png:9个
5星 · 超过95%的资源 需积分: 49 51 下载量 59 浏览量
2019-03-25
17:18:19
上传
评论
收藏 709KB RAR 举报
温馨提示
实现网络打印机打印,可调取网络打印机发送打印打印指令进行打印
资源推荐
资源详情
资源评论
收起资源包目录
php实现网络打印机打印 (143个子文件)
demo.bin 72KB
bit-image.bin 10KB
graphics.bin 9KB
receipt-with-logo.bin 9KB
character-tables.bin 8KB
barcode.bin 3KB
pdf417-code.bin 2KB
character-encodings.bin 2KB
qr-code.bin 2KB
text-size.bin 368B
margins-and-spacing.bin 339B
canvas_white.bmp 142B
canvas_black.bmp 142B
black_white.bmp 138B
escpos.doxyfile 100KB
canvas_black.gif 72B
canvas_white.gif 72B
black_white.gif 65B
black_transparent.gif 65B
.gitignore 169B
document.html 17KB
escpos-php-development.iml 399B
character-encoding-test-strings.inc 3KB
black_white.jpg 175B
canvas_black.jpg 160B
canvas_white.jpg 160B
capabilities.json 55KB
composer.json 1KB
composer.lock 44KB
Makefile 547B
FAQ.md 9KB
CONTRIBUTING.md 3KB
README.md 2KB
LICENSE.md 1KB
CONTRIBUTORS.md 995B
README.md 444B
README.md 223B
README.md 20KB
document.odt 39KB
document.pdf 24KB
doc.pdf 7KB
Printer.php 43KB
EscposTest.php 35KB
EscposImage.php 15KB
WindowsPrintConnector.php 13KB
WindowsPrintConnectorTest.php 12KB
EscposPrintBufferTest.php 10KB
ImagickEscposImage.php 10KB
EscposPrintBuffer.php 10KB
CapabilityProfile.php 9KB
barcode.php 9KB
CodePage.php 5KB
CupsPrintConnector.php 5KB
ImagickEscposImageTest.php 5KB
demo.php 5KB
ExampleTest.php 5KB
AuresCustomerDisplay.php 4KB
ImagePrintBuffer.php 4KB
GdEscposImageTest.php 3KB
character-tables.php 3KB
GdEscposImage.php 3KB
receipt-with-logo.php 3KB
print-from-html.php 3KB
LegacyCapabilityProfileTest.php 3KB
print-from-pdf.php 3KB
pdf417-code.php 3KB
39-currency-symbols.php 3KB
character-encodings.php 3KB
6-arabic-epos-tep-220m.php 3KB
character-encodings-with-images.php 2KB
qr-code.php 2KB
AuresCustomerDisplayTest.php 2KB
ApiPrintConnector.php 2KB
CodePageTest.php 2KB
smb.php 2KB
CapabilityProfileTest.php 2KB
54-gfx-sidebyside.php 2KB
PrintBuffer.php 2KB
FilePrintConnector.php 2KB
UriPrintConnectorTest.php 2KB
DummyPrintConnector.php 2KB
text-size.php 2KB
margins-and-spacing.php 1KB
32-german-tm-t20-ii-custom-command.php 1KB
UriPrintConnector.php 1KB
CupsPrintConnectorTest.php 1KB
141-custom-command.php 1KB
NetworkPrintConnector.php 1KB
148-data-uri.php 1KB
bit-image.php 1KB
PrintConnector.php 1KB
customer-display.php 1KB
44-pound-symbol-star-tsp650.php 1KB
linux-usb.php 1KB
windows-usb.php 1KB
graphics.php 1KB
29-latvian-star-tup592.php 1KB
37-chinese.php 1002B
windows-lpt.php 982B
bootstrap.php 979B
共 143 条
- 1
- 2
资源评论
- 金山文档2023-07-24通过这个文件,我了解到了如何使用PHP实现网络打印机打印,让我对PHP的应用范围有了更深入的认识。
- 经年哲思2023-07-24这个文件提供了简洁有效的解决方案,让网络打印机的使用更加方便。
- 朱王勇2023-07-24文件中提供的代码示例简单易懂,即使是对PHP不太熟悉的人也能够轻松上手。
- 刘璐璐璐璐璐2023-07-24这个文件将网络打印机的打印功能与PHP技术巧妙地结合,为开发者节省大量研究和开发时间。
- 阿汝娜老师2023-07-24这个文件清晰地介绍了如何使用PHP来实现网络打印机的打印功能,非常实用。
qq_37063915
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功