2017-08-24 314 views

回答

1

可以使用window.print()

这里是热敏打印机在我的发票打印代码

<p align="center"><input type="button" id="pr" value="Print" onclick="printpage()" class="btn btn-success" /></p> 

<script type="text/javascript"> 
    function printpage() { 
     var printButton = document.getElementById("printingDiv"); 
     printButton.style.visibility = 'hidden'; 

     document.title = ""; 
     document.URL = ""; 

     window.print(); 
     printButton.style.visibility = 'visible'; 


    } 
</script> 
+0

感谢您的回复。我会尝试这一个。 – user3283395

0

我最近使用Mike42/escpos的PHP我minithermal M-58 POS打印机。这是一个php插件,它将通过网络将您的php应用程序与高分辨率打印机连接起来。这是我用简单的代码在热敏打印机上打印一些文字。

try { 
     // Enter the share name for your USB printer here 
     //$connector = "POS-58"; 
     //$connector = new WindowsPrintConnector("POS-58"); 
     $connector = new WindowsPrintConnector("smb://yourPrinterIP"); 
     /* Print a "Hello world" receipt" */ 
     $printer = new Printer($connector); 
     /* Name of shop */ 
     $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH); 
     $printer->setJustification(Printer::JUSTIFY_CENTER); 
     $printer->text("POS Mart\n"); 
     $printer->selectPrintMode(); 
     $printer->text("Today Closing.\n"); 

     $printer->feed(); 
     /* Title of receipt */ 
     $printer->setEmphasis(true); 

     $printer->feed(2); 

     /* Cut the receipt and open the cash drawer */ 
     $printer->cut(); 
     $printer->pulse(); 
     /* Close printer */ 
     $printer->close(); 
     // echo "Sudah di Print"; 
     return true; 
    } catch (Exception $e) { 
     $message = "Couldn't print to this printer: " . $e->getMessage() . "\n"; 
     return false; 
    } 

所有你需要的是您的打印机IP地址添加到你的PHP代码printconnector或者如果您使用USB线连接到打印机上,您可以使用自己的IP作为PHP代码printconnector。

-1

试试这段代码: $ connector = new WindowsPrintConnector(“smb:// computername/Receipt Printer”);

相关问题