【问题标题】:PHP Printing - How do I print directly from PHP on local server printer?PHP 打印 - 如何在本地服务器打印机上直接从 PHP 打印?
【发布时间】: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" &gt; LPT1吗?出于故障排除原因
  • 你在评论中写了 LTP1,它应该是 LPT1,假设这个错字在这里与你的问题无关?
  • @Eddy 好吧,不是真的告诉我文件找不到文件。我该怎么办?
  • @RoAchterberg 编辑了帖子,我的错。
  • 打印机已连接并共享到 LPT1 端口。你是如何确定的?

标签: php laravel printing


【解决方案1】:

来源被评论并告诉您以下内容。

来自https://github.com/mike42/escpos-php/blob/master/example/interface/windows-usb.php

/**
 * 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
 */

来自https://github.com/mike42/escpos-php/blob/development/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php

/**
 * Connector for sending print jobs to
 * - local ports on windows (COM1, LPT1, etc)
 * - shared (SMB) printers from any platform (smb://server/foo)
 * For USB printers or other ports, the trick is to share the printer with a
 * generic text driver, then connect to the shared printer locally.
 */

查看这些关于如何共享打印机的文章:

【讨论】:

    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 2011-11-06
    • 2014-05-30
    • 2011-06-24
    相关资源
    最近更新 更多