Skip to main content
ava74628296
Inspiring
February 17, 2016
Question

Save A copy

  • February 17, 2016
  • 1 reply
  • 1063 views

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

This topic has been closed for replies.

1 reply

karthickm50893796
Inspiring
February 17, 2016

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;

  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;

}

ava74628296
Inspiring
February 18, 2016

Thanks!

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

Idiagram
Participating Frequently
September 11, 2017

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

}