8 Replies Latest reply on May 25, 2012 4:20 AM by Muppet Mark

    Script: print to PostScript

    Flavien.06

      Hello


      I need help to complete a script.
      I must regularly convert. Have to. Ps
      I would like to make a batch on a folder.

      I tried recording an action script illustrator but always select the default print.

      I find this script on the forum
      But I still have the same problem it selects the default printer, how to force it to use the PostScript printer

      Thank you

      var docs = app.documents;

      var docCount = docs.length;

       

      // if there are opened documents, print them, otherwise ask for a folder to batch print

      if (docCount>0) {

          alert(docCount);

          printOpenDocs(docs);

      }

      else {

      var folder = Folder.selectDialog("Select Source Folder..."); // select folder

       

      printFolder(folder);

      }

       

      // Prints and closes each open document

      function printOpenDocs(docs) {

                  for (j=docCount-1; j>=0; j--) {

                      var jdoc = docs[j];

                      jdoc.print(options);

       

                      jdoc.close(SaveOptions.

      DONOTSAVECHANGES);
                  }
      }

       

      function printFolder(folder) {
          if (folder==null) {
                  alert("Good Bye");
          }

       

          else {
              var files = folder.getFiles ("*.ai"); // get files
              var fileCount = files.length; // count them

       

              if (fileCount>0) {
                  for (i=0; i<fileCount; i++) {
                      var idoc = app.open(files[i]);
                      idoc.print();
                      idoc.close();
                  }
              }
              else {
                  alert("There are no Illustrator files in this folder.");
              }
          }
      }

        • 1. Re: Script: print to PostScript
          Muppet Mark Level 5

          Have you tried creating a print preset in AI then passing it to print as options… This can also be done by script but print options are more complex…

          • 2. Re: Script: print to PostScript
            Flavien.06 Level 1

            Yes I created  print preset PostScript but I can not use them in a batch processing.

            • 3. Re: Script: print to PostScript
              Muppet Mark Level 5

              Your line of syntax…

               

              idoc.print();

               

              Contains no options as a parameter so it's just going to default…

               

              You can get the options just the once then pass on each print() in the loop?

              • 4. Re: Script: print to PostScript
                Larry G. Schneider Adobe Community Professional & MVP

                Sure you can. Here's a page from the JS Reference (as displayed from Jongware's OMV reference) which should give you a start

                 

                Screen shot 2012-05-24 at 9.15.33 AM.png

                • 5. Re: Script: print to PostScript
                  Flavien.06 Level 1

                  thank you,

                  but I don't know how to use the "jdoc.print" syntax  ?

                   

                   

                    var jdoc = docs[j];

                    jdoc.print(options:printerName.'PostScript');

                  ??

                  • 6. Re: Script: print to PostScript
                    Muppet Mark Level 5

                    This should give you a decent enough start…

                     

                    #target illustrator
                    
                    printPostScript();
                    
                    function printPostScript() {
                        
                        app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
                        
                        var docPath, docs, inFolder, opts, psPath;
                        
                        jobOpts = new PrintJobOptions();
                        
                        opts = new PrintOptions();
                         
                        opts.printPreset = 'PostScript';
                        
                        opts.jobOptions =  jobOpts;
                        
                        if ( app.documents.length > 0 ) {
                            
                            docs = app.documents;
                            
                        } else {
                           
                           inFolder = Folder.selectDialog( 'Select Source Folder...' );
                           
                            if ( inFolder != null ) {
                           
                                docs = inFolder.getFiles( '*.ai' );
                            
                           };
                           
                        };
                    
                    
                        for ( i = docs.length-1; i >= 0; i-- ) {
                            
                            if ( docs[i] instanceof File ) {
                                
                                app.open( docs[i] );
                                
                            } else {
                                
                                app.activeDocument = docs[i];
                            
                            };
                        
                            docPath = decodeURI( app.activeDocument.fullName );
                        
                            psPath = docPath.replace( /.ai$/, '.ps' );
                        
                            jobOpts.file = File( psPath );
                    
                            app.activeDocument.print( opts );
                    
                            app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );
                             
                        };
                    
                        app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
                        
                    };
                    
                    • 7. Re: Script: print to PostScript
                      Flavien.06 Level 1

                      Thank you it works perfectly

                      • 8. Re: Script: print to PostScript
                        Muppet Mark Level 5

                        As is… It presumes any open documents are saved and are of *.ai filetype too… But you can adjust to suit your needs…