PHP打印-如何在本地服务器打印机上直接从PHP打印?
我想从本地服务器自动将文档打印到POS打印机 我试过迈克的方法,但没有用,这是我的代码PHP打印-如何在本地服务器打印机上直接从PHP打印?,php,laravel,printing,Php,Laravel,Printing,我想从本地服务器自动将文档打印到POS打印机 我试过迈克的方法,但没有用,这是我的代码 <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Mike42\Escpos\PrintConnectors\FilePrintConnector; use Mike42\Escpos\Printer; use Mike42\Escpos\PrintConnectors\WindowsPrintConnect
<?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();
}
源代码被注释并告诉您以下内容
发件人:
和来自:
请参阅以下有关如何共享打印机的文章:
您可以在命令行上执行echo“Hello World”>LPT1
?出于故障排除的原因,你在评论中写下了LTP1,应该是LPT1,假设这个打字错误与你的问题无关?@Eddy嗯,不是真的,它告诉我该文件找不到该文件。我该怎么办?@RoAchterberg编辑了这篇文章,我的错。打印机已连接并共享到LPT1端口。你是怎么决定的?
/**
* 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
*/
/**
* 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.
*/