printer_open

(PECL)

printer_open -- Open connection to a printer

Description

resource printer_open ( [string devicename] )

This function tries to open a connection to the printer devicename, and returns a handle on success or FALSE on failure.

If no parameter was given it tries to open a connection to the default printer (if not specified in php.ini as printer.default_printer, PHP tries to detect it).

printer_open() also starts a device context.

例子 1. printer_open() example

<?php
$handle
= printer_open("HP Deskjet 930c");
$handle = printer_open();
?>

add a note add a note User Contributed Notes
denny at wardhana dot net
25-Nov-2005 12:06
The codes will only works if the printer attached to the server.
As far as I know, the client side printing by requesting data from server can be done by using javascript (ie. client side scripting) and/or XML

I wonder if there is the way to "php print" on the remote clients (such as Point of Sales)
philip
30-Mar-2005 06:39
This function may also return NULL on failure, instead of FALSE.
jt at jtis dot de
31-Aug-2004 06:39
Revision: Single quotes DO work, but with a triple slash, like
printer_open('\\\SERVERNAME\PRINTERNAME');

Weird.
jt at jtis dot de
31-Aug-2004 04:42
To the Editor's Note below:
It might be more efficient so use single quotes and might look nicer, but it does NOT work. (Not for me at least: Win 2K, Apache 1.3.27, PHP 5.0.1)
Error message says: "Printer \SERVERNAME\PRINTERNAME not found".

Using "\\\\SERVERNAME\\PRINTERNAME" does work perfectly and apart from the nanoseconds wasted for parsing the string I do not see why I should not use it. :-)
jasonlam_ at hotmail dot com
05-Jun-2003 07:22
[Editor's Note:]
You can use single quotes instead for two reasons:
 - PHP isn't parsing string in single quotes, so
   it's a bit resource friendly
 - No parsing, not needed to escape slashes

<?php
   $handle
= printer_open('\\DOMAIN_NAME\Printer_Name');
?>
[/Note]



Connecting to Network Printers
<?php
   $handle
= printer_open("\\\\DOMAIN_NAME\\Printer_Name");
?>
Similiar to how you would locate a domain on your network
you need to have 2 prefix slashes.  But as reminder
you need to escape it.  So really you need 4 slashes.  It
worked me. Hopefully this helps who is having problems
connecting to network printer.
csammis at iastate dot edu
01-May-2002 10:38
As stated on the index page for all the printer functions, these are supported under Win32 *only*...in fact, they're frontends API calls. I'd go ahead and say that they would probably never be ported to *nix because of the many various ways of handling printers. Windows, for all its faults, at least has a unified printing system.

As to editing the php.ini, try it with no path at all, like the first example here
k.fijalkowski(at)interia.pl
04-Feb-2002 12:06
Look your php.ini file and remark
extension=php_printer.dll