Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/325582-printing-shipping-labels-directly/
Share on other sites

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...

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. 

 

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 by PHP5000

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>

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.