1

I have some output that I would like to send over a network printer:

$printoutput .="<tr><td width='10%'> Item #". ($i+1) ."</td></tr> 
                            <tr width='20%'><td>  " . $product_name . " --&nbsp;$" . $price . ".00</td></tr>
                            <tr><td width='40%'>" . $displayoptions . "</td>
                            <tr><td>&nbsp;</td></tr>";

The above all works perfectly within my script when I echo the printoutput variable. This information is a receipt of the users selections. What i'd like to do is create a button that will automatically send over $printoutput to a local network printer.

I want it to be as simple as possible, without any print dialogs - a simple click button, send over data to local network printer.

I've been researching online, and haven't really found anything useful for this. the onClick="window.print()" function brings up a print dialog screen, then only prints that content on the page.

I've looked into printer_openin the PHP Manual, but I am not sure if I am heading in the right direction. Does anyone have any experience with this? Any help would be greatly appreciated. Any bit of code that can lead me in the right direction would be even better.

1 Answer 1

0

If the printer is truly "local" and it is connected to the server that the PHP is running on, and the server is Linux you could do something like:

$cmd = 'echo '.$printoutput.' | lpr';

$response = shell_exec($cmd);

If you are trying to print to the "remote" printer, i.e. the printer is connected to a machine that the browser is running on, or if you want the browser to render your HTML before printing, I'm afraid Javascript's window.print() is pretty much your only option. It always pops the "Printer Select" window for security reasons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.