PHP printing to local Thermal Printer, does not work without networkname

孤人 提交于 2020-01-01 05:45:08

问题


I've build a POS (Point of Sale) application in PHP that can print directly to a thermal printer. In most cases i run the application on a local webserver using WAMP.

Part of the printing code is:

$printer = "\\\\localhost\\TM-T88V";

// Open connection to the thermal printer
$fp = fopen($printer, "w");
if (!$fp){
  die('no connection');
}

$data = " PRINT THIS ";

// Cut Paper
$data .= "\x00\x1Bi\x00";

if (!fwrite($fp,$data)){
  die('writing failed');
}

This code works fine as long as the PC is connected to a network. I can get PHP to connect to a shared printer (either on the same pc, or on a pc in the network) by using fopen and "LOCALHOST" or "COMPUTER-NAME" : fopen("\\localhost\TM-T88V",'w');

If I disconnect the pc from the network, PHP can no longer connect to \\localhost or \\COMPUTER-NAME.

I've tried things like: fopen('TM-T88V'), fopen('\\.\TM-T88V'), but I keep getting "[function.fopen]: failed to open stream: No such file or directory...".

How do I connect to a local (shared) printer (preferably by name) without having an active network connection?


回答1:


Have you tried fopen("PRN", "w")?




回答2:


Here is the code snippet I am using for my print job in PHP :

$handle = printer_open('Printer Name in windows here');

if($handle) { // Make sure the printer is present before sending the job
// print job here
}


来源:https://stackoverflow.com/questions/10268479/php-printing-to-local-thermal-printer-does-not-work-without-networkname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!