(PECL printer SVN)

printer_openApre la connessione ad una stampante


mixed printer_open ([ string $NomePeriferica ] )

Questa funzione tenta di aprire una connessione con la stampante NomePeriferica, e restituisce un handle se ha successo oppure FALSE se fallisce.

Se non vengono passati parametri, la funzione tenta di aprire una connessione con la stampante di default (se non viene specificata in php.ini come printer.default_printer, il PHP tenta di determinarla).

Inoltre printer_open() attiva un device context.

Example #1 Esempio di utilizzo di printer_open()

printer_open("HP Deskjet 930c");
$handle printer_open();
add a note add a note

User Contributed Notes 6 notes

John Middleton
5 years ago
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 printer_open("\\\\\\printername"); ?>

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

= "\\\\\\printername");
$ph = printer_open($printer))
// Get file contents
$fh = fopen("filename.ext", "rb");
$content = fread($fh, filesize("filename.ext"));
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content);
"Couldn't connect...";
9 years ago
This function may also return NULL on failure, instead of FALSE.
Sunny Chan from HK
4 years ago
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.
jasonlam_ at hotmail dot com
10 years ago
Connecting to Network Printers
= 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.
knightcon at bluebottle dot com
7 years ago
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.
jt at jtis dot de
9 years ago
Revision: Single quotes DO work, but with a triple slash, like

To Top