thilino / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 0 forks source link

Printing on multiple printers #138

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. trying to print on 3 printers and calling applet.isDoneFinding() and 
applet.isDonePrinting() in loops
2.
3.

What is the expected output? What do you see instead?
the expected output is that the receipts should get printed on three printers. 
what I get is that the applet and java crashes and I think this happens after 
the first applet.isDonePrinting(). And if I don't call these methods every 
thing is printed on the last printer found

What version of the product are you using? On what operating system?
I am using latest version of jzebra and on google chrome and java 7

Please provide any additional information below.
My code:
var applet = document.jzebra;
findPrinter("kitchen")
while(!applet.isDoneFinding()){}
print()
while(!applet.isDonePrinting()){}
findPrinter("bar")
while(!applet.isDoneFinding()){}
print()
while(!applet.isDonePrinting()){}
findPrinter("shisha")
while(!applet.isDoneFinding()){}
print()
while(!applet.isDonePrinting()){}

Am I doing something wrong. when should I exactly call the methods. is there 
another way to ensure that the printing happens correctly

Original issue reported on code.google.com by mohamedt...@gmail.com on 15 Jun 2013 at 1:06

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
There are warnings in the sample.html to NOT use the while() loops any longer.

This is how I would do it.  (Psuedocode, not tested).

var printers = new Array("office1", "office2", "office3");
var commands = new Array("^XA^FO100,100^BY7^BCN,100,Y,N,N^FD000000^FS^XZ", 
    "^XA^FO100,100^BY7^BCN,100,Y,N,N^FD000001^FS^XZ", 
    "^XA^FO100,100^BY7^BCN,100,Y,N,N^FD000002^FS^XZ")
var counter = 0;

// Find the printer (jzebra will initiate the rest of the commands)
function doPrint() {
    applet.findPrinter(printers[counter]);
}

// If found, send commands
function jzebraDoneFinding() {
    var e = applet.getException();
    if (e != null) {
        applet.print(commands[counter]);
    } else {
       alert("Error! " & e.getLocalizedMessage());
    }   
}

// Incriment counter, print again 
function jzebraDonePrinting() {
    counter++;
    if (counter < printers.length) {
        doPrint();
    } else {
        alert("Printing completed to " + printers.length + " printers!");
    }
}

Original comment by tres.fin...@gmail.com on 18 Jun 2013 at 6:18

GoogleCodeExporter commented 8 years ago
first of all i give you thanks for this library, help me alot in order to 
upgrade my system, im from chile and apologize for my bad english....

thanks again and i hope you can help me.

What steps will reproduce the problem?
1. in my form i can print 3 diferent stickers like: small, medium, large
2. if i choose one of each the printer send all the information to the first 
printer that it found.
3. i have 3 diferent printers and that printers are instaled into the same 
computer with diferent name and diferent ports.

What is the expected output? What do you see instead?
i wanna send 3 diferent sticker to each printer, i dont care if i cant send it 
in the same time.

What version of the product are you using? On what operating system?
im using 1.4.9.1 and my operatig system is windows XP

Please provide any additional information below.
/*
tipo_precio -> have the discriminator in order to select the printer
               (fleje, gnacho, grande)
precio -> have the value to print 
cod_producto -> other value to print
desc_prod -> other value to print
oferta -> have the discriminator in order to print an on sale or normal
          (yes (si), no (no))
*/
function zebra(tipo_precio, precio, cod_producto, desc_prod, oferta){
if(tipo_precio == "fleje"){
tamagno=precio.length;
precio2 = precio.replace(",",".");
precio3 = precio2.replace(",",".");
var printers = new Array("ZebraFleje","ZebraGancho","ZebraGrande");
if(oferta=="si"){
if(tamagno>6){
var etiquetas = 
"\""+"^XA^FO220,60^ARN,130,135^FD"+precio3+"^FS^FO350,190^ARN,2,2^FD"+cod_produc
to+"^FS^FO200,230^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno==6){
var etiquetas = 
"\""+"^XA^FO270,20^ARN,200,150^FD"+precio3+"^FS^FO350,190^ARN,2,2^FD"+cod_produc
to+"^FS^FO200,230^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno<6){
var etiquetas = 
"\""+"^XA^FO320,20^ARN,200,150^FD"+precio3+"^FS^FO350,190^ARN,2,2^FD"+cod_produc
to+"^FS^FO200,230^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
}
else{
if(tamagno>6){
var etiquetas = 
"\""+"^XA^FO220,50^ARN,150,125^FD"+precio3+"^FS^FO350,190^ARN,2,2^FD"+cod_produc
to+"^FS^FO200,230^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno==6){
var etiquetas = 
"\""+"^XA^FO270,20^ARN,200,150^FD"+precio3+"^FS^FO350,190^ARN,2,2^FD"+cod_produc
to+"^FS^FO200,230^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno<6){
var etiquetas = 
"\""+"^XA^FO320,20^ARN,200,150^FD"+precio3+"^FS^FO350,190^ARN,2,2^FD"+cod_produc
to+"^FS^FO200,230^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
}
document.jzebra.findPrinter(printers[0]);/*search the printer by name*/
document.jzebra.append(etiquetas);  /*put the variable to print*/ 
document.jzebra.print();
}
if(tipo_precio=="gancho"){
tamagno=precio.length;
precio2 = precio.replace(",",".");
precio3 = precio2.replace(",",".");
if(oferta=="si"){
if(tamagno>=6){
var etiquetas = 
"\""+"^XA^FO100,30^ARN,130,100^FD"+precio3+"^FS^FO150,150^ARN,2,2^FD"+cod_produc
to+"^FS^FO60,200^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno<6){
var etiquetas = 
"\""+"^XA^FO100,30^ARN,130,130^FD"+precio3+"^FS^FO150,150^ARN,2,2^FD"+cod_produc
to+"^FS^FO60,200^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
}
else{
if(tamagno>6){
var etiquetas = 
"\""+"^XA^FO100,5^ARN,130,110^FD"+precio3+"^FS^FO150,150^ARN,2,2^FD"+cod_product
o+"^FS^FO60,200^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno==6){
var etiquetas = 
"\""+"^XA^FO100,5^ARN,150,130^FD"+precio3+"^FS^FO150,150^ARN,2,2^FD"+cod_product
o+"^FS^FO60,200^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
if(tamagno<6){
var etiquetas = 
"\""+"^XA^FO100,5^ARN,150,150^FD"+precio3+"^FS^FO150,150^ARN,2,2^FD"+cod_product
o+"^FS^FO60,200^A0,17,17^FD"+desc_prod+"^FS^XZ"+"\"";
}
}
document.jzebra.findPrinter(printers[1]);/*search the printer by name*/
document.jzebra.append(etiquetas);  /*put the variable to print*/ 
document.jzebra.print();              /*se imprime*/
}
if(tipo_precio=="grande"){
tamagno=precio.length;
precio2 = precio.replace(",",".");
precio3 = precio2.replace(",",".");
if(oferta=="si"){
if(tamagno>=9){
var etiquetas = 
"\""+"^XA^FO140,350^ARN,250,170^FD"+precio3+"^FS^FO600,730^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,650^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno==7){
var etiquetas = 
"\""+"^XA^FO110,350^ARN,300,230^FD"+precio3+"^FS^FO600,730^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,650^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno==6){
var etiquetas = 
"\""+"^XA^FO120,350^ARN,300,230^FD"+precio3+"^FS^FO600,730^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,650^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno==5){
var etiquetas = 
"\""+"^XA^FO120,350^ARN,300,230^FD"+precio3+"^FS^FO600,730^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,650^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno<5){
console.log("grande, oferta, menor a 5");
var etiquetas = 
"\""+"^XA^FO200,350^ARN,300,230^FD"+precio3+"^FS^FO600,730^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,650^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
}
else{
if(tamagno>=9){
var etiquetas = 
"\""+"^XA^FO120,450^ARN,250,170^FD"+precio3+"^FS^FO610,790^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,720^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno==7){
var etiquetas = 
"\""+"^XA^FO120,430^ARN,300,230^FD"+precio3+"^FS^FO610,790^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,720^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno==6){
var etiquetas = 
"\""+"^XA^FO120,430^ARN,300,230^FD"+precio3+"^FS^FO610,790^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,720^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno==5){
var etiquetas = 
"\""+"^XA^FO120,430^ARN,300,260^FD"+precio3+"^FS^FO610,790^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,720^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
if(tamagno<5){
var etiquetas = 
"\""+"^XA^FO200,430^ARN,300,260^FD"+precio3+"^FS^FO610,790^A0,30,30^FD"+cod_prod
ucto+"^FS^FO30,720^ARN,2,2^FD"+desc_prod+"^XZ"+"\"";
}
}
document.jzebra.findPrinter(printers[2]);/*search the printer by name*/
document.jzebra.append(etiquetas);  /*put the variable to print*/ 
document.jzebra.print();    
}           
}

Original comment by abravo.s...@gmail.com on 9 Oct 2013 at 12:48