【问题标题】:Adobe Illustrator script 'Save as copy'Adobe Illustrator 脚本“另存为副本”
【发布时间】:2016-10-17 10:51:15
【问题描述】:

当我设计一个标志时,我需要为客户导出多种格式,这包括以下内容:

• 低分辨率 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;
}

【问题讨论】:

    标签: javascript adobe-illustrator


    【解决方案1】:

    Javascript 区分大小写。我发现你的一个错误,也许还有更多类似的......

    getOptions 函数中你有一行:

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

    这应该改为:

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

    【讨论】:

    • Adobe 文档说要使用小写的 p。脚本参考的第 147 页说使用“pDFPreset”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多