Adobe Illustrator脚本“另存为副本”

时间:2016-10-17 10:51:16

标签: javascript adobe-illustrator

当我设计徽标时,我需要为客户端以多种格式导出徽标,其中包含以下内容:

•低分辨率PDF(通过电子邮件发送给客户批准)

一旦获得批准,我就发出以下信息:

•高分辨率PDF

•JPG

•PSD

基本上我想将我的untitled.ai文件的副本保存为低分辨率PDF并在我的文档名称之后添加_LR,即untitled_LR.PDF

我现在应该在Illustrator中打开2个文档,我原来的.ai文件和我新创建的.pdf文件

我开发了一个脚本,主要是使用现有脚本并将它们全部粘贴在一起,目前这个脚本执行以下操作;

•隐藏名为“说明”的图层

•在徽标周围添加5毫米边框

•刻录徽标

•然后使用选定的PDF预设保存为PDF,并在文档名称后添加文本“_LR”。

这样可以很好地保存1个低分辨率PDF,但它取代了我在Illustrator中的.ai文件,我需要它保存为副本吗?

然后我需要创建第二个脚本,将其作为高分辨率PDF以及JPG和PSD版本保存。

请参阅当前脚本的附加当前Javascript:

#target illustrator

// Hide layers.
var doc = app.activeDocument;  
var myLayers = doc.layers;  
var HideName = "Instructions";  
try {  
    HideLayer = myLayers.getByName (HideName);  
    HideLayer.visible = false;  
    redraw();  
    }  
catch (e) {}

// Add a 5mm border surrounding the logo.
var mm = 2.834645;
var doc = app.activeDocument;
var myVisibleBounds = doc.visibleBounds; //Rect, which is an array;

myVisibleBounds[0] -= 5*mm; //left coordinate (use negative values to add artboard)
myVisibleBounds[1] += 5*mm; //ltop coordinate
myVisibleBounds[2] += 5*mm; //right coordinate
myVisibleBounds[3] -= 5*mm; //bottom coordinate (use negative values to add artboard)

doc.artboards[0].artboardRect = myVisibleBounds;


//  Rasterize Layer by name  
    if ( app.documents.length > 0 ) {  
        doc = app.activeDocument;  
        {  
            createRasterLayer(doc);  
        } 
    }else{  
        Window.alert("You must open at least one document.");  
    }  

function createRasterLayer(doc){  
    var totalLayers = doc.layers.length;  //get the total number of layers in the active document  
    for ( var i = 0 ; i < totalLayers ; i++){  //looping through layers               
        var currentLayer = doc.layers[i];  
        var tempItem;  
        if(currentLayer.visible == false) continue;   //We don't want to deal with hidden layers  
        currentLayer.locked = false;                       //Unlock the layer if needed  
        var layerName = new String( currentLayer.name );  
        if ( layerName.indexOf("Design") == 0 ) { 
            currentLayer.hasSelectedArtwork = true;   //Select ALL in the layer  
            if(doc.visibleBounds[2] == 0) continue;   // ignore empty layers  
            var newoptions = new RasterizeOptions;    
            newoptions.resolution = 72;  
            if ( doc.selection.length > 0 ) {  
                newGroup = app.activeDocument.groupItems.add();  
                for ( z = 0; z < doc.selection.length; z++ ) {  
                    doc.selection[z].move( newGroup, ElementPlacement.INSIDE);  
                   }  
                doc.rasterize (newGroup, newGroup.visibleBounds, newoptions);  
            }  
         }
    }  
}



// Save as PDF


/** Saves every document open in Illustrator
    as a PDF file in a user specified folder.
*/

// 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 Low-Res PDF file.', '~' );

        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.

                sourceDoc = app.activeDocument; // 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( 'Low-Res PDF Saved' );
        }
    }
    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.
    @return PDFSaveOptions object
*/
function getOptions() {
    var NamePreset = 'Proof Hi-Res PDF';
    // Create the required options object
    var options = new PDFSaveOptions();
        options.pDFPreset="[Smallest File Size]";

    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),
    // 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 个答案:

答案 0 :(得分:0)

Javascript区分大小写。我找到了你的一个错误,也许还有更多......

getOptions函数中,您有以下行:

options.pDFPreset="[Smallest File Size]";

这应该改为:

options.PDFPreset="[Smallest File Size]";
相关问题