【问题标题】:Print the invoice using PHP escpos in linux在 Linux 中使用 PHP escpos 打印发票
【发布时间】:2016-01-23 10:51:10
【问题描述】:

我正在实现打印发票的功能,为此我使用了 Escpos 模块,但是当我运行它时没有响应。

如果我打印 php_sapi_name 我得到的是“apache2handler”而不是“cli”,我有 linux 系统。我不知道如何在我的网络服务器中获取“cli”。

您能否分享您解决此问题的想法

if(php_sapi_name() == 'cli') {// i got apache2handler
    $connector = new FilePrintConnector("php://stdout");
} else {
 throw new InvalidArgumentException("Argument passed to Escpos::__construct() must implement interface PrintConnector, null given.");
  }

【问题讨论】:

    标签: php printing command-line-interface escpos


    【解决方案1】:

    由于问题引用了看起来非常熟悉的代码的 sn-p,我假设您指的是 mike42/escpos-php。

    如果是这样,您需要选择适用于您的平台(Windows、Mac、Linux)和接口(USB、串行、Samba 共享、CUPS)的PrintConnector。初始化驱动程序的正确方法是系统特定的。

    README 文件中显示了受支持的组合表以及指向示例 sn-ps 的链接。

    例如,如果您在 Linux 上有 USB 打印机,它可能会显示为 /dev/usb/lp0。假设您的权限配置为允许网络服务器用户访问该文件,发送基本收据的链接在 Linux/USB 下的 README 中:

    <?php
    require __DIR__ . '/vendor/autoload.php';
    use Mike42\Escpos\PrintConnectors\FilePrintConnector;
    use Mike42\Escpos\Printer;
    $connector = new FilePrintConnector("/dev/usb/lp0");
    $printer = new Printer($connector);
    $printer -> text("Hello World!\n");
    $printer -> cut();
    $printer -> close();
    

    除此之外:您引用的 sn-p 不再在代码中,但如果您在命令行上并且没有指定打印连接器,则它是一个旧功能,可以使用 php:///stdout。

    【讨论】:

    • 如果我在 Windows 上有 USB 打印机,我应该将什么传递给 FilePrintConnector()。
    猜你喜欢
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    相关资源
    最近更新 更多