5 Replies Latest reply on Jun 20, 2011 10:48 AM by ctaffe

    Printing from Flex to a Thermal (Zebra ZPL) Printer

    ctaffe

      Anybody have any success (or have any idea) on how to send a print command from Flex to a thermal printer?  I don't want to send it an mxml layout similar to your standard flex print job but rather a ZPL string that describes the print job.

       

      For example, in PHP it would be something akin to:

      $labelcode =<<<AAA
      ^XA
      ^LH0,0
      ^FO40,100^FH\^A0N,50,40^FDCookbook II^FS
      ^FO40,150^CI7^FH\^A0N,30,30^FDFrom Alice Cooker^FS
      ^FO40,180^BY3,2^BCN,150,N,N^FD1234567890ABC^FS
      ^PQ1
      ^XZ
      AAA;
      file_put_contents('/dev/lp0',$label);

        • 1. Re: Printing from Flex to a Thermal (Zebra ZPL) Printer
          Zolotoj Level 3

          You will have to do it from the html wrapper using JS code. Assuming you are using Windows based computer:

          // HTML wrapper. JS functions

          // 1. Load ZPL code

          var fs = new ActiveXObject("Scripting.FileSystemObject");
          objFile = fs.OpenTextFile("\\\\computername_or_IP\\somefolder\\someZPLFile.prn", 1, false);
          var strText = new String();
          strText = objFile.ReadAll();
          objFile.Close();

          // 2. Print

          objPrinter = fs.CreateTextFile("LPT1", true);

          objPrinter.Write(strText);
          objPrinter.Close();

           

          HTH

          1 person found this helpful
          • 2. Re: Printing from Flex to a Thermal (Zebra ZPL) Printer
            ctaffe Level 1

            Thanks for the resopnse.  I'll have to give it a try and let you (and the thread ) know.  Do I need to worry about Flex not allowing this in a release AIR build due to security?

            • 3. Re: Printing from Flex to a Thermal (Zebra ZPL) Printer
              Zolotoj Level 3

              In your original question it was Flex, now it's  AIR?

              • 4. Re: Printing from Flex to a Thermal (Zebra ZPL) Printer
                ctaffe Level 1

                I apologize for the confusion, I meant AIR originally and wasn't specific in the title nor the description of the issue.

                • 5. Re: Printing from Flex to a Thermal (Zebra ZPL) Printer
                  ctaffe Level 1

                  Looking at some .net examples (http://stackoverflow.com/questions/2044676/net-code-to-talk-zpl-to-zebra-printers) and tried to apply some of that thought process to Flex.

                   

                  var file:File = new File('\\\\PC-Name\\Printer-Name');

                  var stream:FileStream = new FileStream();

                  stream.open(file, FileMode.WRITE);

                   

                  The interesting part at this point is watching the printer queue, a new item does pop in there as "Spooling".  However, that is about as promising as this got as the minute I attempted to write data to the stream, the process would actually crash out the debugger. Full code below:

                   

                  var byteArray:ByteArray = new ByteArray();

                  byteArray.writeUTFBytes("Hello World");

                  byteArray.position = 0;

                   

                  var file:File = new File('\\\\PC-Name\\Printer-Name');

                  var stream:FileStream = new FileStream();

                  stream.open(file, FileMode.WRITE);

                  stream.writeBytes(byteArray);

                  // stream.close();

                   

                  I commented out stream.close() because that would throw an I/O error in the debugger immediately (although the error wasn't helpfull enough for me to figure out what the issue is).  Without it, it eventually crashes the debugger completely.  Both are obviously bad

                   

                  This could just be a case of Flex just can't do this.  Had I not seen it trigger a spooling document in the queue I would have abandoned this route awhile ago but that got me hopefull that I was close but just missing something.