【发布时间】:2021-02-22 19:17:42
【问题描述】:
我想将文档从本地服务器自动打印到我的 POS 打印机。
我尝试了 Mike 的方法 https://github.com/mike42/escpos-php,但无济于事,这是我的代码。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
use Mike42\Escpos\CapabilityProfile;
class PrintReceipt extends Controller
{
public function TestPrint(){
$profile = CapabilityProfile::load("simple");
$connector = new WindowsPrintConnector("LPT1");
$printer = new Printer($connector, $profile);
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();
}
但我收到此错误: file_put_contents(LPT1):无法打开流:没有这样的文件或目录 打印机已连接并共享到 LPT1 端口。关于如何修复我的代码或其他解决方法的任何想法?我认为普通打印应该也可以,方法是否用于POS都没关系。
提前谢谢你!
【问题讨论】:
-
你能在命令行上做
echo "Hello World" > LPT1吗?出于故障排除原因 -
你在评论中写了 LTP1,它应该是 LPT1,假设这个错字在这里与你的问题无关?
-
@Eddy 好吧,不是真的告诉我文件找不到文件。我该怎么办?
-
@RoAchterberg 编辑了帖子,我的错。
-
打印机已连接并共享到 LPT1 端口。你是如何确定的?