3 Replies Latest reply on Oct 27, 2016 9:45 AM by Peter Kahrel

    New To ExtendScript

    jseymourcreative

      I am new to ExtendScript. Im still trying to wrap my mind around the Indesign Object Model among other things. Im just fiddling around here trying to do simple tasks. Im having trouble exporting a pdf. Can anyone help me troubleshoot this script?

       

      Main();
      // If you want the script to be un-doable, comment out the line above, and remove the comment from the line below
      // app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
      
      
      function Main() {
        // Check to see whether any InDesign documents are open.
        // If no documents are open, display an error message.
        if (app.documents.length > 0) {
        var myDoc = app.activeDocument;
               myDoc.asynchronousExportFile(PDF,/Users/greer/Desktop/test.pdf,false,SmallestFileSize);
        // Do something here
        alert("Finished!");
        }
        else {
        // No documents are open, so display an error message.
        alert("No InDesign documents are open. Please open a document and try again.");
        }
      }
      
        • 1. Re: New To ExtendScript
          tpk1982 Level 4

          HI,

           

          Line11 is wrong.. have to use quotes for path..please look the below thread..so you got some ideas how to perform

           

          Re: cancelTask() & cancelAllTask()

           

          Script only runs in the Extendscript toolkit

           

          Re: Download PDF Document

          • 2. Re: New To ExtendScript
            cbishop01 Level 2

            Here's a tid bit i came across on here. It will allow you to define your Presets and location.

             

             var myPDFExportPreset = app.pdfExportPresets.item("[Smallest File Size]"); // Change myPDFpreset to the name of the preset you want to use 
             var myFileLocation = Folder.selectDialog("/Volumes/"); // Change this to your FOlder location
                myFolder = new Folder ([myFileLocation]); 
                myFolderContents = myFolder.getFiles("*.indd"); // array 
                myFileAmount = (myFolderContents.length - 1); 
            
                // ===== Open, Export as PDF, and Close files ===== \\  
                for (i = myFileAmount; i >= 0; i--) 
                {  
                app.open(File (myFolderContents[i])); 
                app.activeDocument.exportFile( 
                  ExportFormat.pdfType,  
                  new File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf"), 
                  false,  
                  myPDFExportPreset 
                  ); 
                app.activeDocument.close(SaveOptions.no); 
            
                }  
            
            • 3. Re: New To ExtendScript
              Peter Kahrel Adobe Community Professional & MVP

              The problem is that you use strings for the document and the preset, where you should use file and preset objects. The correct form of your export statement is as follows:

               

              myDoc.asynchronousExportFile (ExportFormat.PDF_TYPE, File ('/Users/greer/Desktop/test.pdf'), false, app.pdfExportPresets.item('[Smallest File Size]'))
              

               

              Peter