我们正在为货币兑换商开发基于PHP的Web应用程序。我们正在使用的货币兑换商使用POS(EPSON TM-U220D)打印机来接收客户收据,因此我们正在寻找一种从Web应用程序打印到POS打印机的方法,我们尝试使用mike42 / escpos-php PHP库并使用它使USB收据打印机可以在Windows教程上运行,但是不起作用。这是我们第一次使用POS打印机,因此我们完全迷失了。有人可以帮忙吗?提前致谢。 详细信息:
Printer : [EPSON TM-U220D][1]
PHP Library : [Mike42/Escpos-php][1]
Tutorial : [Getting a USB receipt printer working on Windows][1]
Programming Languages : [PHP 7.2.0][1]
Web Server : [Apache][1]
Database : [MySQL][1]
代码:
/*
// Call this file 'hello-world.php'
require __DIR__ . '/inc/escpos/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();
*/
/* Change to the correct path if you copy this example! */
require __DIR__ . '/inc/escpos/vendor/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";
}
答案 0 :(得分:0)
希望这会帮助其他人。 您需要先安装驱动程序。然后,如下所示编写代码。 WindowsPrintConnector是用于创建连接器对象的一种。这对Laravel来说对我有用。
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
use Mike42\Escpos\Printer;
require 'C:\wamp64\www\myappname\vendor\autoload.php';
try {
// Enter the share name for your USB printer here
$connector = null;
$connector = new WindowsPrintConnector("E-PoS 80mm Thermal 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";
}