githubashto / jzebra

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

Changing printer #49

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I cannot seem to change printers to print a different document. See code below.
function print2()
{
    printPDF();
    print();
}
function print() {
         var applet = document.jZebra;
            findPrinter('zebra');
             if (applet != null) {
                applet.append("^XA");;
                applet.append("^FO32,10^AdN,0,0^FWN^FH^FDRECIPIENT COMPANY NAMERECIPIENT COMPANY NAMERECIPIENT COMPANY NAMERECIPIENT COMPANY NAME^FS");
                applet.append("^XZ");

                // Send characters/raw commands to printer
                applet.print();
            }
                monitorPrinting();
        }
function printPDF() {
         // Make sure pdf-renderer.jar is in the "./lib" folder
         // Append the PDF
        var applet = document.jZebra;
            findPrinter('hp');
             if (applet != null) {
                applet.appendPDF(window.location.href + "/../sample.pdf");
            }
            monitorAppending2();
      }

Original issue reported on code.google.com by rvtecrv...@gmail.com on 14 Mar 2012 at 6:35

GoogleCodeExporter commented 9 years ago
It seems monitorAppending(); needs to be called in print(). See print function 
below.
function print() {
         var applet = document.jZebra;
            findPrinter('zebra');
             if (applet != null) {
                applet.append("^XA");;
                applet.append("^FO32,10^AdN,0,0^FWN^FH^FDRECIPIENT COMPANY NAMERECIPIENT COMPANY NAMERECIPIENT COMPANY NAMERECIPIENT COMPANY NAME^FS");
                applet.append("^XZ");

            }
                monitorAppending();
        }

Original comment by rvtecrv...@gmail.com on 14 Mar 2012 at 6:51

GoogleCodeExporter commented 9 years ago
You have a couple of things going on here.  Since Java (or any browser plugin) 
can easily deadlock the browser, jZebra was specifically written with all of 
its events  on a background thread.  This is why we check things like 
"isDoneFinding()", "isDoneAppending()", and then "isDonePrinting()" as well as 
check "getException()".

I've provided basic examples of this with "monitorAppending()", but it's very 
basic code, and doesn't leverage some of the newer asynchronous abilities of 
jQuery, etc.

  - The advantage of this approach is that the browser is responsive and the developer has direct control over the front end.
  - The disadvantage is everything must be done asynchronously from the front-end, meaning you need to write code that waits for stuff to happen before you can proceed.

So, if you want to print to two different printers immediately following one 
another, you need to write your own "monitorAppending()" that actually waits 
until printing is done on the first printer before executing the print command 
on the second printer.

A better long term approach would be for me to add a feature that queues events 
and execute them in the order they were supplied.  This would probably be a 
good enhancement write up, but would be an entire re-write of the JavaScript 
listener thread, and likely require quite a bit of regression bug testing.

-Tres

Original comment by tres.fin...@gmail.com on 14 Mar 2012 at 8:29

GoogleCodeExporter commented 9 years ago
I'm also facing a similar issue.

I have a dropdown of all the printer a user has and when user selects the 
printer it fires the print command to the selected printer. But if user changes 
the printer after that, the java console says the new printer was selected, but 
it still tries to print on the previous selected printer.

Is there any way can I change to the new selected printer?

Original comment by jainnik...@gmail.com on 17 Mar 2012 at 9:25

GoogleCodeExporter commented 9 years ago
Ok, 
I found out the reason for this issue.
I was printing HTML, so when looking at the src I found this function
[code]    private PrintHTML getPrintHTML() {
        if (this.printHTML == null) {
            this.printHTML = new PrintHTML();
            this.printHTML.setPrintParameters(this);
        }
        return printHTML;
    }
[/code]

here this.printHTML.setPrintParameters(this); only set when printHTML in null 
so I changed it to
[code]    
private PrintHTML getPrintHTML() {
    if (this.printHTML == null) {
        this.printHTML = new PrintHTML();
    }
        this.printHTML.setPrintParameters(this);
        return printHTML;
}
[/code]

 and it resolved the issue for the html print issue.

Original comment by jainnik...@gmail.com on 17 Mar 2012 at 12:05

GoogleCodeExporter commented 9 years ago
I'm also experiencing a similar issue.

Am using printPDF() to print 2 pdf files to 2 different printers.
Ive createt a javascript queue but even this dosnt work, 

Both prints gets sent to the wrong printer even thoug the java console sais 
that the correct printer is selectet 

Here is a copy from the console:

25.mar.2012 20:13:50 jzebra.LogIt log
INFO: ===== JAVASCRIPT LISTENER THREAD STOPPED =====
25.mar.2012 20:13:50 jzebra.LogIt log
INFO: jZebra 1.3.5
25.mar.2012 20:13:50 jzebra.LogIt log
INFO: ===== JAVASCRIPT LISTENER THREAD STARTED =====
25.mar.2012 20:13:50 jzebra.LogIt log
INFO: Current printer charset encoding: windows-1252
25.mar.2012 20:13:50 jzebra.LogIt log
INFO: ===== SEARCHING FOR PRINTER =====
25.mar.2012 20:13:50 jzebra.LogIt log
INFO: Found 7 attached printers.
25.mar.2012 20:13:50 jzebra.LogIt log
INFO: Printer specified: \Qzebra\E
25.mar.2012 20:13:50 jzebra.LogIt log
WARNING: Printer not found: \Qzebra\E
25.mar.2012 20:13:55 jzebra.LogIt log
INFO: ===== SEARCHING FOR PRINTER =====
25.mar.2012 20:13:55 jzebra.LogIt log
INFO: Found 7 attached printers.
25.mar.2012 20:13:55 jzebra.LogIt log
INFO: Printer specified: \QBrother QL-560\E
25.mar.2012 20:13:55 jzebra.LogIt log
INFO: Printer name match: Brother QL-560
25.mar.2012 20:13:55 jzebra.LogIt log
INFO: Using best match: Brother QL-560
25.mar.2012 20:13:57 jzebra.LogIt log
INFO: Printer set to index: 2,  Name: Brother QL-560
25.mar.2012 20:13:57 jzebra.LogIt log
INFO: ===== SENDING DATA TO THE PRINTER =====
25.mar.2012 20:13:57 jzebra.LogIt log
INFO: 

    <<http://samplepdf.com/sample.pdf>>

25.mar.2012 20:13:57 jzebra.LogIt log
INFO: Using PDF renderer: com.sun.pdfview.PDFFile
25.mar.2012 20:14:05 jzebra.LogIt log
INFO: ===== SEARCHING FOR PRINTER =====
25.mar.2012 20:14:05 jzebra.LogIt log
INFO: Found 7 attached printers.
25.mar.2012 20:14:05 jzebra.LogIt log
INFO: Printer specified: \QXPS\E
25.mar.2012 20:14:05 jzebra.LogIt log
INFO: Printer name match: Microsoft XPS Document Writer
25.mar.2012 20:14:05 jzebra.LogIt log
INFO: Using best match: Microsoft XPS Document Writer
25.mar.2012 20:14:07 jzebra.LogIt log
INFO: Printer set to index: 5,  Name: Microsoft XPS Document Writer
25.mar.2012 20:14:07 jzebra.LogIt log
INFO: ===== SENDING DATA TO THE PRINTER =====
25.mar.2012 20:14:07 jzebra.LogIt log
INFO: 

        <<http://samplepdf.com/sample.pdf>>

Original comment by orjan.la...@gmail.com on 25 Mar 2012 at 6:22

GoogleCodeExporter commented 9 years ago

Original comment by tres.fin...@gmail.com on 30 May 2012 at 1:09

GoogleCodeExporter commented 9 years ago
This should be fixed with version 1.4.0.  Confirmation needed.

Original comment by tres.fin...@gmail.com on 7 Jun 2012 at 1:42

GoogleCodeExporter commented 9 years ago
Reported as fixed by Orjan with 1.4.1.  Closing, marking as fixed.  Feel free 
to reopen if this was done in error.

Original comment by tres.fin...@gmail.com on 12 Jun 2012 at 2:31