qzindustries / qz-print

Free browser applet for sending documents and raw commands to a printer.
Other
49 stars 4 forks source link

re-init setOrientation #34

Closed jensdeschrijver closed 10 years ago

jensdeschrijver commented 10 years ago

Hi

The plugin works fine for me to print shipping labels from different carriers with a Zebra printer. By one carrier, I get a PDF portrait label, with the other carrier I get a landscape png image.

I use the printPDF() or printImage() functions for this. Additionally, I've added a orientation for these with the function setOrientation.

When I load the page (and the plugin) and print the first label in landscape, then the printer does everything right. When I try to print another label in portrait, then the printer still prints the label in landscape. (the other way around, is the same effect).

I there a possibility to reset or re-initialize the orientation every time I print, without reloading the page/plugin?

The function:

    /***************************************************************************
    * Prototype function for printing a graphic to a PostScript capable printer.
    * Not to be used in combination with raw printers.
    * Usage:
    *    qz.appendImage('/path/to/image.png');
    *    window['qzDoneAppending'] = function() { qz.printPS(); };
    ***************************************************************************/ 
    function printImage(file, orientation) {
        if (notReady()) { return; }

        // Optional, set up custom page size.  These only work for PostScript printing.
        // setPaperSize() must be called before setAutoSize(), setOrientation(), etc.

        qz.setPaperSize("101.6mm", "152.4mm");  // US Letter
        qz.setAutoSize(true);
        if(!orientation) {
            var orientation = 'landscape';
        }
        qz.setOrientation(orientation);

        //qz.setOrientation("landscape");
        //qz.setOrientation("reverse-landscape");
        //qz.setCopies(3); //Does not seem to do anything

        // Append our image (only one image can be appended per print)
        qz.appendImage(file);

        // Automatically gets called when "qz.appendImage()" is finished.
        window['qzDoneAppending'] = function() {
            // Tell the applet to print PostScript.
            qz.printPS();

            // Remove reference to this function
            window['qzDoneAppending'] = null;
        };
    }

    /***************************************************************************
    * Prototype function for printing a PDF to a PostScript capable printer.
    * Not to be used in combination with raw printers.
    * Usage:
    *    qz.appendPDF('/path/to/sample.pdf');
    *    window['qzDoneAppending'] = function() { qz.printPS(); };
    ***************************************************************************/ 
    function printPDF(file, orientation) {
        if (notReady()) { return; }

        qz.setPaperSize("101.6mm", "152.4mm");  // US Letter
        qz.setAutoSize(true);
        if(!orientation) {
            var orientation = 'portrait';
        }
        qz.setOrientation(orientation);
        //qz.setOrientation("reverse-landscape");
        //qz.setCopies(3); //Does not seem to do anything

        // Append our pdf (only one pdf can be appended per print)
        if(!file) {
            var file = "http://shopwedo.com/admin/assets/js/qzprint/misc/pdf_sample.pdf";
            //var file = getPath() + "misc/pdf_sample.pdf";
        }
        qz.appendPDF(file);

        // Automatically gets called when "qz.appendPDF()" is finished.
        window['qzDoneAppending'] = function() {
            // Tell the applet to print PostScript.
            qz.printPS();

            // Remove reference to this function
            window['qzDoneAppending'] = null;
        };
    }
tresf commented 10 years ago

I believe this has been corrected after fixing issue #24 as both orientation and page size are stored in the same variable which wasn't getting set. Which version are you using?

I've uploaded 1.8.7 here: http://qzindustries.com/download

Please test and verify if this still exists in the latest build.

jensdeschrijver commented 10 years ago

Hi Tres

This update fixes the problem about orientation. It also fixes the issues with Google Chrome.

Thanks!!