Link to home
Start Free TrialLog in
Avatar of ullenulle
ullenulleFlag for United States of America

asked on

How to send specific forms to printer on save?

Hi out there.

I have a challenge: I made a webdatabase in Classic asp with a MySQL backend. When the user saves a form with a few variables, those variables must be sent to a printer (a Zebra GK420t label printer). I tried different solutions, but there I get the header and footer from the browser as well, and sometimes nothing at all. I want the specific variables only to be printed, AND they must be setup to fill the labels... like inserting </br> and also control font-size.
I would appreciate BIG time if anyone can come up with a solution! :-)

Best regards

Ulrich
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might be able to set your page to trusted and set trusted to low security with appropriate javascript settings so you don't get certificate errors. This of course is assuming that this is run internally.
Avatar of ullenulle

ASKER

Hello all.
Thank you for your responses so far. I'll dig into it in a few days.
Best regards
Ulrich
I've requested that this question be closed as follows:

Accepted answer: 500 points for Scott Fell's comment #a40720730

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Hi Scott.

Please accept my apology for my lack of response. I still didn't get to test your suggestion, but as soon as I do, I will let you know how it worked out. :-)

Best regards

Ulrich
Thank you.
Hello everyone.

A long lasting issue has been solved, and I like to share the solution in here to help others. The soloution could be done in pure JavaScript and simply added to my pages before the </body> tag:

<script type="text/javascript" src="../r_lab/demo/js/qz-websocket.js"></script>
<script type="text/javascript">
deployQZ();
function getCertificate(callback) {
    callback("-----BEGIN CERTIFICATE-----\n" +
        ".... Looooooooooooots of certificate codes....+
        "-----END CERTIFICATE-----\n");
}
function signRequest(toSign, callback) {
    callback();
}
    function qzDonePrinting() {
        if (qz.getException()) {
            alert('Error printing:\n\n\t' + qz.getException().getLocalizedMessage());
            qz.clearException();
            return;
        }
   }	
function findPrinters() {
      qz.findPrinter('\\{bogus_printer\\}');
}
function qzDoneFinding() {
      var printers = qz.getPrinters().replace(/,/g, '\n');
}
function findPrinter(name) {
    var p = document.getElementById('printer');
    if (name) {
        p.value = name;
    }
        qz.findPrinter(p.value);
        window['qzDoneFinding'] = function() {
            var p = document.getElementById('printer');
            var printer = qz.getPrinter();
            window['qzDoneFinding'] = null;
        };
}
function printZPL() {
	qz.findPrinter('Zebra');
	qz.setEncoding(850);
    var get_proevemateriale = document.getElementById('proevemateriale').value;
	var get_projectname = document.getElementById('projectname').value;
	var get_boxname = document.getElementById('boxname').value;
	var get_proeve_date = document.getElementById('proeve_date').value;
	var get_diagnose = document.getElementById('diagnose').value;
    qz.append('^XA');
	qz.append('^FS^FO20,30^ADN36,25^FD');
	qz.append(get_proevemateriale);
	qz.append('^FS^FO20,55^ADN36,25^FD');
	qz.append(get_projectname+' - '+get_proeve_date);
	qz.append('^FS^FO20,80^ADN36,25^FD');
	qz.append(get_boxname);
	qz.append('^FS^FO20,105^ADN36,25^FD');
	qz.append(get_proeve_date);
	qz.append('^FS^FO20,130^ADN36,25^FD');
	qz.append(get_diagnose);
    qz.append('^FS');
    qz.append('^XZ');
    qz.print();
    }
</script>

Open in new window



function printZPL()  at the end of the codes are the one to edit in order to make the printed labels look as planned. Data is being pulled from forms on the webpage. QZ provided lots of support to make it Work. It all appears so easy when it finally Works. :-)

Best regards

Ulrich
>It all appears so easy when it finally Works.

That is correct. Tres is very helpful with his product.

It looks like what you are doing is sending data probably via asp/vb to different html elements like

<div id="proevemateriale">some text here</div>

Open in new window


Your line 40 above grabs the text "some text here" then line 47 outputs that text.  Line 46 and 48 are the RAW codes that adjust things like fonts and spacing.

What I have done instead of sending data to an element is just place it directly to a js variable or directly to the print command.\

Instead of your line 47 above
qz.append(get_proevemateriale);

Open in new window

I have simply used
<%
' ASP CODE
proevemateriale = "some text"
%>

<!-- code inside <script> tag for js -->
qz.append(<%=proevemateriale%>);

Open in new window


Then  no need to create html elements (unless of course you are also sending this to screen)