php 调用未定义的函数 printer_open()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15338132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:04:39  来源:igfitidea点击:

Call to undefined function printer_open()

phpprinting

提问by Sriniwas

I am trying to connect to my printer which is on another machine through this code

我正在尝试通过此代码连接到另一台机器上的打印机

     $handle = printer_open("\\xxx.xxx.xxx.xxx\Canon MF4320-4350");
     if($handle)
     echo "connected";
     else
     echo "not connected";     

and getting the error

并得到错误

    Fatal error: Call to undefined function printer_open() in C:\wamp\www\print\index.php on line 3

I have installed the php_printer.dll but it is not showing it under phpinfo(). Using PHP version 5.3.0

我已经安装了 php_printer.dll 但它没有在phpinfo(). 使用 PHP 5.3.0 版

how can i connect to the printer and make my printer_open()method work??

如何连接到打印机并使我的printer_open()方法起作用?

回答by Placid

If you are using PHP 5.3/ 5.4/ 5.5 in WAMP, here is how you setup printer.

如果您在 WAMP 中使用 PHP 5.3/5.4/5.5,这里是您设置打印机的方法。

  1. Go to this link:http://windows.php.net/downloads/pecl/snaps/printer/0.1.0-dev/
  2. Download the zip for your version. First try with ts. If it does not work, try nts.
  3. Unzip and copy the php_printer.dll file. Paste here: C:\wamp\bin\php(phpyourversion)\ext . Note: (phpyourversion) will be like php5.5.12 depending on your version.
  4. Find the loaded php.ini file. Use phpinfo or Wamp menu to find it. Look online for more help.
  5. Paste this at the end of the file: extension=php_printer.dll
  6. Restart server.
  7. Create a file with the following code and test it:

    <?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);

  8. If the above does not work, try with nts version of the php_printer.dll file as mentioned in step two. remember to restart server after deleting the previous file, pasting the new file.

  1. 转到此链接:http: //windows.php.net/downloads/pecl/snaps/printer/0.1.0-dev/
  2. 下载适用于您的版本的 zip。首先尝试使用 ts。如果它不起作用,请尝试nts。
  3. 解压并复制 php_printer.dll 文件。粘贴在这里: C:\wamp\bin\php(phpyourversion)\ext 。注意: (phpyourversion) 将类似于 php5.5.12,具体取决于您的版本。
  4. 找到加载的 php.ini 文件。使用 phpinfo 或 Wamp 菜单找到它。在线查找更多帮助。
  5. 将此粘贴到文件末尾:extension=php_printer.dll
  6. 重启服务器。
  7. 使用以下代码创建一个文件并测试它:

    <?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);

  8. 如果上述方法不起作用,请尝试使用第 2 步中提到的 php_printer.dll 文件的 nts 版本。记得删除以前的文件后重新启动服务器,粘贴新文件。

回答by user2090145

I have a similar problem. This is what I have figured out so far.

我有一个类似的问题。这是我到目前为止想出来的。

  1. Make sure that you have a php_printer.dll matching your php compile version in your extension folder ( php/ext/ ). Use this linkfor downloading the file.

  2. add the following in your php.ini file:

    printer.default_printer=PHP_INI_ALL
    extension=php_printer.dll
    
  1. 确保您的扩展文件夹 ( php/ext/ ) 中有一个与您的 php 编译版本匹配的 php_printer.dll。使用此链接下载文件。

  2. 在 php.ini 文件中添加以下内容:

    printer.default_printer=PHP_INI_ALL
    extension=php_printer.dll
    

The errors have disappeared but the file is still not printing.

错误已消失,但文件仍未打印。