我正在尝试通过此代码连接到另一台机器上的打印机
$handle = printer_open("\\\\xxx.xxx.xxx.xxx\\Canon MF4320-4350");
if($handle)
echo "connected";
else
echo "not connected";
Run Code Online (Sandbox Code Playgroud)
并得到错误
Fatal error: Call to undefined function printer_open() in C:\wamp\www\print\index.php on line 3
Run Code Online (Sandbox Code Playgroud)
我已经安装了 php_printer.dll 但它没有在phpinfo(). 使用 PHP 5.3.0 版
如何连接到打印机并使我的printer_open()方法起作用?
如果您在 WAMP 中使用 PHP 5.3/5.4/5.5,这里是您设置打印机的方法。
使用以下代码创建一个文件并测试它:
<?php
$printer_name = "Your Printer Name exactly as it is";
$handle = printer_open($printer_name);
printer_start_doc($handle, "My Document");
printer_start_page($handle);
$font = printer_create_font("Arial", 100, 100, 400, false, false, false, 0);
printer_select_font($handle, $font);
printer_draw_text($handle, 'This sentence should be printed.', 100, 400);
printer_delete_font($font);
printer_end_page($handle);
printer_end_doc($handle);
printer_close($handle);
如果上述方法不起作用,请尝试使用第 2 步中提到的 php_printer.dll 文件的 nts 版本。记得删除以前的文件后重新启动服务器,粘贴新文件。