2 Replies Latest reply: Dec 6, 2009 9:04 AM by epsobolik RSS

    How does printerList work?

    epsobolik Community Member

      I'm trying to write a javascript script that prints an Adobe Illustrator CS2 (V12.0.1) document using a specific printer.  In the process of doing that, I tried experimenting with displaying a list of available printers - the example in reference for the PrinterInfo object...

       

      var docRef = documents.add();
      var textRef = docRef.textFrames.add();
      var iCount = printerList.length;
      textRef.contents = "Checking Printers... \n";
      textRef.contents += documents.length
      for (var i = 0; i < iCount; ++i) {
          textRef.contents += printerList[i].name + "\n";
          textRef.contents += "\tPS Level = " + printerList[i].printerInf.postScriptLevel + "\n";
          textRef.contents += "\tDevice resolution = " + printerList[i].printerInf.deviceResolution + "\n";
          textRef.contents += "\tInRIPSeparation support = " + printerList[i].printerInf.inRIPSeparationSupport + "\n";
      }
      textRef.top = 600;
      textRef.left = 200;
      redraw();

       

      It fails on line 4:

      Error 1200: an Illustrator error occurred:

      1128353364 ('CANT')

      Line: 4

      -> var iCount = printerList.length;

       

      I've had luck with other collections (see the documents.length above).  Is there something I'm missing?  Is the object name incorrect?  Is it possible to have 0 printers and therefore an empty collection?

       

      The code to print using a specific printer is:

      var printerOpts = new ActiveXObject("Illustrator.PrintOptions");
      printerOpts.printerName = "AutoCDLabels";
      doc.print(printerOpts);

       

      I'm doing this from a stand-alone javascript.  This gives an error on the doc.print line:

      Error:  an Illustrator error occurred: 1128353364('CANT')

      Code:  8001FFFF

       

      Any ideas?

       

      Phil

        • 1. Re: How does printerList work?
          Muppet Mark-QAl63s Community Member

          Phil, I had a problem with 'printerList' myself. So I had a look at your script (bare in mind Im pretty new to JavaScript)

           

          It would appear that although printerList is a property of app it is only available whilst a doc is open (which is where I was falling over)

           

          In your case your script ensures that this is the case by creating a new one first.

           

          Your script worked for me with one or two minor tweeks (a typo that returned undefined throughout)

           

          'printerInf' should have been 'printerInfo'

           

          I also changed the line endings to returns like so:

           

          #target illustrator

           

          var docRef = documents.add();

           

          var textRef = docRef.textFrames.add();

           

          var iCount = printerList.length;

           

          textRef.contents = "Checking Printers... \r";

          textRef.contents += "Open documents = " + documents.length + "\r" + "\r"

           

          for (var i = 0; i < iCount; ++i) {

              textRef.contents += printerList[i].name + "\r";

              textRef.contents += "\tPS Level = " + printerList[i].printerInfo.postScriptLevel + "\r";

              textRef.contents += "\tDevice resolution = " + printerList[i].printerInfo.deviceResolution + "\r";

              textRef.contents += "\tInRIPSeparation support = " + printerList[i].printerInfo.inRIPSeparationSupport + "\r" + "\r";

          }

           

          textRef.top = 600;

          textRef.left = 200;

          redraw();

           

          So I think cases where a new doc is not being created this should be checked like so:

           

          #target illustrator

           

          with (app) {

          if (documents.length > 0) {

          var iCount = printerList.length;

          $.write(iCount);

          }

          else {

          alert('This ONLY works when a doc is open?');

          }

          }

           

          As for your 'ActiveXObject' I do NOT Know of this so can't help & 'stand-alone javascript' what do you mean by this? Out side of ESTK?

          • 2. Re: How does printerList work?
            epsobolik Community Member

            Thanks for replying.  I saw that a document had to be opened in order for printerList to be valid.  The code I used is from the documentation that is included with Acrobat.

             

            I'm running under Windows, so /n is better than /r.  /r will go to the beginning of the same line.

             

            Windows has a scripting environment - WSH - Windows Scripting Host - that allows JavaScript (JScript, technically) or VB Script (or any other scripting language that some one wants to implement) to run at a DOS prompt.  You get access to the file system, etc. via ActiveX objects.  So, to use Acrobat scripting without being in Illustrator, you just create an Illustrator.Application ActiveXObject and proceed.  I wanted to update the version in a bunch of CD label image files.

             

            I ended up creating a print preset in Illustrator with the printer that I wanted to use and then selected that preset in the script.  I went a step further in my printerList search, however.  I found the ExtendScript development environment and opened a document.  Lo and behold, printerList was invalid.  I could browse other stuff, but not printerList.  I think there is something messed up with the interface to Windows printers - not an uncommon situation.  Anyway, I got what I wanted done.

             

            Phil