Printer 函数
在线手册:中文  英文

printer_open

(PECL printer SVN)

printer_openOpens a connection to a printer

说明

resource printer_open ([ string $printername ] )

This function tries to open a connection to the given printer.

printer_open() also starts a device context.

参数

printername

The printer name. 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).

返回值

Returns a printer handle on success 或者在失败时返回 FALSE.

范例

Example #1 printer_open() example

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


Printer 函数
在线手册:中文  英文

用户评论:

Sunny Chan from HK (2009-06-18 21:03:22)

If you cannot print on a client shared printer, you may create a admin user account, and assign it to run Apache under Windows Service.

John Middleton (2009-03-20 10:09:00)

I had been playing around with trying to get PHP to print to a network server off and on for quite some time, and I finally came across somebody who had the piece of the puzzle I've been missing.

Like I said, the printer I've been trying to print to is a network printer, so I had been trying to open the printer as follows:

<?php printer_open("\\\\servername\\printername"); ?>

What I had been missing is that the function needed the internet host name of the server, which includes the domain name.  So, let's say my print server was called "PServer" and my network's domain was called php.net:

<?php printer_open("\\\\Pserver.php.net\\printername"); ?>

This will more than likely work, then you can open and print a file as follows:

<?php
$printer 
"\\\\Pserver.php.net\\printername");
if(
$ph printer_open($printer))
{
   
// Get file contents
   
$fh fopen("filename.ext""rb");
   
$content fread($fhfilesize("filename.ext"));
   
fclose($fh);
        
   
// Set print mode to RAW and send PDF to printer
   
printer_set_option($phPRINTER_MODE"RAW");
   
printer_write($ph$content);
   
printer_close($ph);
}
else 
"Couldn't connect...";
?>

knightcon at bluebottle dot com (2006-12-14 17:04:22)

If you are desperate to do server-side printing with PHP on a *nix machine then you can always use the fsockopen() function and send a pre-build PJL (Printer Job Language) string directly to the printer. As long as your printer supports PJL then there should be no problem. Just also bare in mind that unless you are doing something very special, like sending the print job to a remote printer and not the printer the client is at you should just make a report page generated by php and apply a css stylesheet which makes the page styled for printing.

philip (2005-03-29 14:39:17)

This function may also return NULL on failure, instead of FALSE.

jt at jtis dot de (2004-08-31 03:39:23)

Revision: Single quotes DO work, but with a triple slash, like
printer_open('\\\SERVERNAME\PRINTERNAME');
Weird.

jasonlam_ at hotmail dot com (2003-06-04 16:22:27)

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 (2002-04-30 19:38:56)

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

易百教程