Printing from web clients to there directly connected printers might seem tricky from within a php script, while php enables you to directly print documents to a printer in a windows environment, this means that the printer is attached to the server (on which php resides!), while we generally aim at printing at the client side this needs some further environment configuration...
In a windows client/server environment where the client is a web browser and the server is the php enabled web server and the printer is attached to each client, please do the following to be able to print to the client's directly connected printer:
1 - install the printer driver on both the server and the client machines; php needs the driver on the server to connect to the printer and the client needs the driver to know there's a printer!.
2 - share the printer on the client machine with a unique name related to the client computer name, e.g. if the client computer name is "PC01" name it's attached printer share name as "PC01-PRINTER" so there's a portion of the name which is static "-PRINTER" and the other is dynamic "PC01".
3 - from a php script you can access the printer of each client (if you have many) which utilize the server's php script!!, how this is done??
Refering to PHP Manual http://www.php.net/manual/en/ref.printer.php
jason at matteson dot com wrote a comment in that section its brief conclusion a nice function to access the printer by it's shared name
function getPrinter($SharedPrinterName) {
global $REMOTE_ADDR;
$host = getHostByAddr($REMOTE_ADDR);
return "\\".$host."\".$SharedPrinterName;
}
$handle = printer_open(getPrinter("Eltron"));
how can i know it's name if i have multiple clients??, simply my modified version of jason's function is as follows:
function getClientPrinter() {
$host = getHostByAddr($_SERVER['REMOTE_ADDR']);
return "\\".$host."\".$host.'-PRINTER';
}
$handle = printer_open(getClientPrinter());
which enables you to dynamically select the client and the printer!!!, ...this is a solution i hope to PHP/Windows Client WebApps Printing, where the shared printer network name is used for communication.