問題描述
我有一個問題困擾了我至少 3 周.我需要使用 php 將一些數據打印到打印機.我將數據保存到 $print_output
變量中,我知道我的數據很好,因為當我通過電子郵件發送它時,它顯示了應該顯示的所有內容.
I have a question that has been troubling me for at least 3 weeks now. I need to print some data to a printer using php. I have data saved into a $print_output
variable, and I know my data is good because when I send it via email, it shows everything that is supposed to be shown.
好吧,我試著寫了這段代碼,我以為我可以測試它,但不確定它是否會起作用.
Well, I tried writing this code, where I thought I could test it but wasn't sure if it would have even worked.
$handle = printer_open("\\192.168.1.33_4\Printer_Office");
printer_set_option($handle, PRINTER_MODE, "raw");
printer_write($handle,$print_output);
printer_close($handle);
好吧,結果我沒有安裝 php_printer.dll 擴展,我被告知不要重新編譯 php 來添加它.
Well, turns out I don't have php_printer.dll extension installed and I was told not to re-compile php to add it.
我想要做的只是將存儲在 $print_output
中的數據打印到同一網絡上的打印機.我不想使用 javascript 函數 window.print()
因為我無法彈出打印對話屏幕.
What I'd like to do is simply print out the data that is stored in $print_output
to a printer on my same network. I don't want to use the javascript function window.print()
because I can't have a print dialogue screen pop up.
有沒有人有任何信息可以為我指明正確的方向?或者另一種直接將少量數據打印到打印機而不使用 php 的 printer_open
函數的方法?
Does anyone have any information that can point me in the right direction? Or another way to simply print a small amount of data directly to the printer without using php's printer_open
function?
推薦答案
對于遇到同樣問題的任何人,我發現我可以簡單地使用套接字編程推送數據,如下所示.下面的ip地址是我打印機的ip地址.如果您愿意,您可以通過 telnet 連接到您的打印機,以確保連接能夠正常工作.
For anyone who is having the same trouble, I figured out I can simply push the data using socket programming as follows. The ip address below is my printer's ip address. You can telnet into your printer to make sure the connection works beforehand if you'd like.
if(isset($_POST['order'])){
$print_output= $_POST['order'];
}
try
{
$fp=pfsockopen("192.168.1.33", 9100);
fputs($fp, $print_output);
fclose($fp);
echo 'Successfully Printed';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "
";
}
這篇關于使用 PHP 將數據打印到打印機的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!