3 Replies Latest reply on Sep 11, 2017 7:47 AM by Idiagram

    Save A copy

    ava74628296 Level 1

      Hi

      I want to save the PDF file, and the file AI file remain active, The method 'saveAs' makes the active PDF file.

      I can do Save A copy?

      Thanks in advance

        • 1. Re: Save A copy
          karthickm50893796 Level 1

          Hi ava

          Try this one

           

          try {

            if (app.documents.length > 0 ) {

                  var destFolder = null;

            destFolder =  ('~/desktop');

           

           

            if (destFolder != null) {

            var options, i, sourceDoc, targetFile;

                  options = this.getOptions();

            for ( i = 0; i < app.documents.length; i++ ) {

            sourceDoc = app.documents[i];

            targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);

           

            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);

          }

          function getOptions()

          {

            var options = new PDFSaveOptions();

            return options;

          }

           

           

          function getTargetFile(docName, ext, destFolder) {

            var newName = "";

              if (docName.indexOf('.') < 0) {

            newName = docName + ext;

            } else {

            var dot = docName.lastIndexOf('.');

            newName += docName.substring(0, dot);

            newName += ext;

            }

            var myFile = new File( destFolder + '/' + newName );

            if (myFile.open("w")) {

            myFile.close();

            }

            else {

            throw new Error('Access is denied');

            }

            return myFile;

          }

          • 2. Re: Save A copy
            ava74628296 Level 1

            Thanks!

            But it does not work, still active file becomes a PDF file

            • 3. Re: Save A copy
              Idiagram Level 1

              I had the same issue exporting to SVG.  This script works for me: exports as SVG (you can change to PDF), then saves-back the current file to .ai so the current AI file/window doesn't change format.

               

              ––––––––––––––––--

               

              // we put the whole program into the function doEverything so that we can use return to terminate execution on an error.
              doEverything();

              function doEverything() {

               

                 // Export the file to SVG - this will change the current open file from .ai to .svg
                 var dest = app.activeDocument.path + "/" + app.activeDocument.name;
                 exportFileToSVG(dest);

                 // Now save as a .ai file - both to save our work, and to change the open file back to .ai from .svg
                 app.activeDocument.save(dest, SaveOptions.SAVECHANGES );
              }

               

              // Exports current document to dest as an SVG file with specified
              // options, dest contains the full path including the file name
              // Unfortunately, it still REPLACES the current AI doc with the SVG doc.

              function exportFileToSVG (dest) {

                 if ( app.documents.length > 0 ) {

                 var exportOptions = new ExportOptionsSVG();
                 var type = ExportType.SVG;
                 var fileSpec = new File(dest);
                 exportOptions.embedRasterImages = true;
                 exportOptions.embedAllFonts = false;
                 exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
                 app.activeDocument.exportFile( fileSpec, type, exportOptions );
                 }

              }