PHP5000 Posted November 20 Share Posted November 20 Hello everybody. What I am trying to do is add a button on a web page that clicking on it will send 3 lines of text (an address) directly to an assigned printer that prints labels. I recall from old days of using VB this was an easy task with that language. However I can not find any information about PHP or JS to do the same thing. Any ideas or examples would be highly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/ Share on other sites More sharing options...
requinix Posted November 20 Share Posted November 20 Where is the printer? Is it connected to the client or to the server? If it's connected to the client then the only thing you can do is present a print dialog. The user will have to choose the printer (potentially) and hit the button to print. If it's connected to the server then you can use a library to have PHP print the page. The details of that depend on what you're printing... Quote Link to comment https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/#findComment-1641045 Share on other sites More sharing options...
Phi11W Posted November 20 Share Posted November 20 7 hours ago, PHP5000 said: ... a button on a web page that ... will send ... text ... to an assigned printer that prints labels. I recall from old days of using VB this was an easy task ... The architecture is completely different. VB programs run on the user's computer and so have access to everything connected to the user's computer. PHP applications run on a web server computer somewhere "out there", on The Web. Your PHP application cannot know anything about any printer, much less interact with them [directly] in any way. To "print" things these days, your PHP application sends document content to the user's web browser (running on the user's computer) and the user can choose to print it from there. For example: https://stackoverflow.com/questions/52410546/create-write-and-download-a-txt-file-using-php Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/#findComment-1641052 Share on other sites More sharing options...
PHP5000 Posted November 20 Author Share Posted November 20 (edited) Hi Thanks for the replies. The printer is a small label printer assigned as default printer to the computer the viewer will use to see the page. Alternatively it could be put on the network with an IP. Pill the thread you linked shows how to generate a separate document, which could be done for each shipping label and then printing the label. I was trying to avoid having to go two steps for the users, which I guess you mean it is not possible with php. I will read more on print related commands of PHP and JS, meanwhile if you guys can think of a solution let me know. Thanks. Edited November 20 by PHP5000 Quote Link to comment https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/#findComment-1641063 Share on other sites More sharing options...
Barand Posted November 20 Share Posted November 20 Is this any use to you? <!DOCTYPE html> <html lang="en"> <head> <title>Wordle Assist</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <style type='text/css'> @media print { .printme { visibility: visible; display: block; } .noprint { visibility: hidden; } } #print { font-family: "times new roman", serif; font-size: 20pt; } #address { margin: 50px; line-height: 40px; } </style> <script type='text/javascript'> $(function() { if ($("#address").text() != '') { print() } }) </script> </head> <body> <div id='address' class='printme'> <?= nl2br($_GET['addy'] ?? '') ?> </div> <header class='noprint'> <h1>Address Labels</h1> </header> <form class='noprint'> Address:<br><br> <textarea cols='60' rows='5' name='addy'></textarea> <br><br> <button id=btnPrint'>Print</button> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/#findComment-1641066 Share on other sites More sharing options...
PHP5000 Posted November 23 Author Share Posted November 23 Thanks Barand Quote Link to comment https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/#findComment-1641143 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.