note 89731 deleted from function.printer-open by sobak
| From: | sobak@php.net | Date: | Thu, 24 Nov 2016 20:31:49 +0000 |
| Subject: | note 89731 deleted from function.printer-open by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207580@lists.php.net to get a copy of this message | ||
Note Submitter: John Middleton
----
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($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...";
?>