开发者

To print a page of web page

I want to print the page content in the printer. I use the follow开发者_Python百科ing code to write the content to printer:

<?php
$printer = "\\\\Pserver.php.net\\printername";
if($ph = printer_open($printer))
{
   // Get file contents
   $fh = fopen("filename.ext", "rb");
   $content = fread($fh, filesize("filename.ext"));
   fclose($fh);

   // Set print mode to RAW and send PDF to printer
   printer_set_option($ph, PRINTER_MODE, "RAW");
   printer_write($ph, $content);
   printer_close($ph);
}
else "Couldn't connect...";
?>

but I found out that it returns an error like printer_open($printer) is undefined function. Where's the fault in the code?


http://php.net/manual/en/function.printer-open.php

This is only Windows function (according to: http://www.php.net/manual/en/intro.printer.php)

So there can be just few reasons

  1. You are not running server on Windows
  2. You don't have this extension installed (see: http://www.php.net/manual/en/printer.installation.php)
  3. You don't have this extension enabled (see phpinfo() to check it)

You have to compile that extension manually or download pack with version according to your PHP version, since it is not downloadable via PECL


See this comment, since it looks like you're trying to print on network shared printer

http://www.php.net/manual/en/ref.printer.php#89054

If you want to print to a network printer on another machine:

If you are running PHP on a web server that is running as the System user (quite likely), it won't have access to network resources, including network printers. Changing the web server service to run as an account with access to network printers fixes the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜