4 Replies Latest reply on May 2, 2017 4:13 PM by spaceheat

    Artboard Range Code for "Save Open Docs as PDF"

    spaceheat Level 1

      I would like to be able to define the Artboard range for my custom "Save Docs as PDF" script. I don't know Java, but I am guessing that I need to insert...

       

      var saveOptions = new PDFSaveOptions();
        saveOptions.artboardRange = 1;
      

       

      into my existing script somewhere, which I've pasted here.

       

      If any one cares, this code that i've pieced together so far allows you to define a specific PDF preset as well as a custom suffix to be added onto the filename.

       

      /**********************************************************
      
      
      ADOBE SYSTEMS INCORPORATED 
      Copyright 2005-2006 Adobe Systems Incorporated 
      All Rights Reserved 
      
      
      NOTICE:  Adobe permits you to use, modify, and 
      distribute this file in accordance with the terms
      of the Adobe license agreement accompanying it.  
      If you have received this file from a source 
      other than Adobe, then your use, modification,
      or distribution of it requires the prior 
      written permission of Adobe. 
      
      
      *********************************************************/
      
      
      /** Saves every document open in Illustrator
        as a PDF file in a user specified folder. Additional language added to control the PDF Preset and to append the file name with a custom suffix.
      */
      
      
      // Main Code [Execution of script begins here]
      
      
      try {
        // uncomment to suppress Illustrator warning dialogs
        // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
      
      
        if (app.documents.length > 0 ) {
      
      
        // Get the folder to save the files into
        var destFolder = null;
        destFolder = Folder.selectDialog( 'Select folder for PDF files.', '~' );
      
      
        if (destFolder != null) {
        var options, i, sourceDoc, targetFile;
      
        // Get the PDF options to be used
        options = this.getOptions();
        // You can tune these by changing the code in the getOptions() function.
      
        for ( i = 0; i < app.documents.length; i++ ) {
        sourceDoc = app.documents[i]; // returns the document object
      
        // Get the file to save the document as pdf into
        targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);
      
        // Save as pdf
        sourceDoc.saveAs( targetFile, options );
        }
        alert( 'Documents saved as PDF' );
        }
        }
        else{
        throw new Error('There are no document open!');
        }
      }
      catch(e) {
        alert( e.message, "Script Alert", true);
      }
      
      
      /** Returns the options to be used for the generated files. --CHANGE PDF PRESET BELOW--
        @return PDFSaveOptions object
      */
      function getOptions()
      {var NamePreset = 'Proof High Res PDF';
        // Create the required options object
        var options = new PDFSaveOptions();
           options.pDFPreset="Proof High Res PDF";
        // See PDFSaveOptions in the JavaScript Reference for available options
        // SET ARTBOARD RANGE HERE?
      
        // Set the options you want below:
      
      
        // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)
        // options.compatibility = PDFCompatibility.ACROBAT7;
      
        // For example, uncomment to view the pdfs in Acrobat after conversion
        // options.viewAfterSaving = true;
      
        return options;
      }
      
      
      /** Returns the file to save or export the document into.
        @param docName the name of the document
        @param ext the extension the file extension to be applied
        @param destFolder the output folder
        @return File object
      */
      function getTargetFile(docName, ext, destFolder) {
        var newName = "_HR";
      
      
        // if name has no dot (and hence no extension),--CHANGE FILE SUFFIX HERE, DEFINE SUFFIX ABOVE--
        // just append the extension
        if (docName.indexOf('.') < 0) {
        newName = docName + ext;
        } else {
        var dot = docName.lastIndexOf('.');
        newName = docName.substring(0, dot)+newName;
        newName += ext;
        }
      
        // Create the file object to save to
        var myFile = new File( destFolder + '/' + newName );
      
        // Preflight access rights
        if (myFile.open("w")) {
        myFile.close();
        }
        else {
        throw new Error('Access is denied');
        }
        return myFile;
      }
      
        • 1. Re: Artboard Range Code for "Save Open Docs as PDF"
          Silly-V Adobe Community Professional

          The artboard range is a string, just like one you can manually input when manually saving the pdf. You can even string several ranges together via hyphens and commas to create an export which skips pages. Example: "1-3,5-7"

           

          PDFSaveOptions.artboardRange  

          Data Type: string

          Adobe Illustrator 21 Type Library

          Considered for multi-asset extraction which specifies artboard range.Empty string will extracts all the artboards.Default is empty string.

          • 2. Re: Artboard Range Code for "Save Open Docs as PDF"
            spaceheat Level 1

            Thanks for the reply. How would I define this string in the above code?

             

            I will be using it on a AI file that has two artboards and I need the code to save a PDF that just uses Artboard 1, instead of saving a multi-page pdf with both artboards.

             

            I found these properties in another post. Would something like this be able to work?

             

            1. saveOpts.saveMultipleArtboards = true
            2. saveOpts.artboardRange = "1"; // artboard # 1 
            • 3. Re: Artboard Range Code for "Save Open Docs as PDF"
              Silly-V Adobe Community Professional

              yes, you just put the string into double quotes and assign via the (=) equals sign.

              • 4. Re: Artboard Range Code for "Save Open Docs as PDF"
                spaceheat Level 1

                Thank you for your guidance Silly-V. In case anyone is interested, Here is the final code...

                 

                /**********************************************************
                
                
                ADOBE SYSTEMS INCORPORATED 
                Copyright 2005-2006 Adobe Systems Incorporated 
                All Rights Reserved 
                
                
                NOTICE:  Adobe permits you to use, modify, and 
                distribute this file in accordance with the terms
                of the Adobe license agreement accompanying it.  
                If you have received this file from a source 
                other than Adobe, then your use, modification,
                or distribution of it requires the prior 
                written permission of Adobe. 
                
                
                *********************************************************/
                
                
                /** Saves every document open in Illustrator
                  as a PDF file in a user specified folder. Additional language added to control the PDF Preset, Set the Artboard range as desired, and to append the file name with a custom suffix.
                */
                
                
                // Main Code [Execution of script begins here]
                
                
                try {
                  // uncomment to suppress Illustrator warning dialogs
                  // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
                
                
                  if (app.documents.length > 0 ) {
                
                
                  // Get the folder to save the files into
                  var destFolder = null;
                  destFolder = Folder.selectDialog( 'Select folder for PDF files.', '~' );
                
                
                  if (destFolder != null) {
                  var options, i, sourceDoc, targetFile;
                
                  // Get the PDF options to be used
                  options = this.getOptions();
                  // You can tune these by changing the code in the getOptions() function.
                
                  for ( i = 0; i < app.documents.length; i++ ) {
                  sourceDoc = app.documents[i]; // returns the document object
                
                  // Get the file to save the document as pdf into
                  targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);
                
                  // Save as pdf
                  sourceDoc.saveAs( targetFile, options );
                  }
                  alert( 'Documents saved as PDF' );
                  }
                  }
                  else{
                  throw new Error('There are no document open!');
                  }
                }
                catch(e) {
                  alert( e.message, "Script Alert", true);
                }
                
                
                /** Returns the options to be used for the generated files. --CHANGE PDF PRESET, ARTBOARD RANGE BELOW--
                  @return PDFSaveOptions object
                */
                function getOptions()
                {var NamePreset = 'Proof High Res PDF';
                  // Create the required options object
                  var options = new PDFSaveOptions();
                     options.saveMultipleArtboards = true; 
                     options.artboardRange = "1";
                     options.pDFPreset="Proof High Res PDF";
                  // See PDFSaveOptions in the JavaScript Reference for available options
                
                  // Set the options you want below:
                
                
                  // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)
                  // options.compatibility = PDFCompatibility.ACROBAT7;
                
                  // For example, uncomment to view the pdfs in Acrobat after conversion
                  // options.viewAfterSaving = true;
                
                  return options;
                }
                
                
                /** Returns the file to save or export the document into.
                  @param docName the name of the document
                  @param ext the extension the file extension to be applied
                  @param destFolder the output folder
                  @return File object
                */
                function getTargetFile(docName, ext, destFolder) {
                  var newName = "_HR";
                
                
                  // if name has no dot (and hence no extension),--CHANGE FILE SUFFIX HERE, DEFINE SUFFIX ABOVE--
                  // just append the extension
                  if (docName.indexOf('.') < 0) {
                  newName = docName + ext;
                  } else {
                  var dot = docName.lastIndexOf('.');
                  newName = docName.substring(0, dot)+newName;
                  newName += ext;
                  }
                
                  // Create the file object to save to
                  var myFile = new File( destFolder + '/' + newName );
                
                  // Preflight access rights
                  if (myFile.open("w")) {
                  myFile.close();
                  }
                  else {
                  throw new Error('Access is denied');
                  }
                  return myFile;
                }