Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Adobe Illustrator脚本';另存为副本';_Javascript_Adobe Illustrator - Fatal编程技术网

Javascript Adobe Illustrator脚本';另存为副本';

Javascript Adobe Illustrator脚本';另存为副本';,javascript,adobe-illustrator,Javascript,Adobe Illustrator,当我设计徽标时,我需要为客户端导出多种格式的徽标,这包括以下内容: •低分辨率PDF(通过电子邮件发送给客户审批) 批准后,我将发送以下信息: •高分辨率PDF •JPG •私营部门司 基本上,我希望将我的untitled.ai文件的副本保存为低分辨率PDF,并在我的文档名(即untitled_LR.PDF)后添加_LR 我现在应该有两个文件在illustrator中打开,我的原始.ai文件和我新创建的.pdf文件 我开发了一个脚本,主要是使用现有的脚本并将它们粘贴在一起,目前这个脚本执行以下操

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

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

批准后,我将发送以下信息:

•高分辨率PDF

•JPG

•私营部门司

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

我现在应该有两个文件在illustrator中打开,我的原始.ai文件和我新创建的.pdf文件

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

•隐藏一个名为“指令”的层

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

•光栅化徽标

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

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

然后,我需要创建第二个脚本,它与JPG和PSD版本一起保存为高分辨率PDF

有关当前脚本,请参见所附的当前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;
}
#目标illustrator
//隐藏图层。
var doc=app.activeDocument;
var myLayers=doc.layers;
var HideName=“指令”;
试试{
HideLayer=myLayers.getByName(HideName);
HideLayer.visible=false;
重画();
}  
捕获(e){}
//在徽标周围添加5毫米边框。
var-mm=2.834645;
var doc=app.activeDocument;
var myVisibleBounds=doc.visibleBounds//Rect,它是一个数组;
myVisibleBounds[0]=5*mm//左坐标(使用负值添加艺术板)
myVisibleBounds[1]+=5*mm//顶坐标
myVisibleBounds[2]+=5*mm//右坐标
myVisibleBounds[3]=5*mm//底部坐标(使用负值添加艺术板)
doc.artboards[0].artboardRect=myVisibleBounds;
//按名称栅格化图层
如果(app.documents.length>0){
doc=app.activeDocument;
{  
createRasterLayer(文档);
} 
}否则{
Window.alert(“您必须至少打开一个文档”);
}  
函数createRasterLayer(doc){
var totalayers=doc.layers.length;//获取活动文档中的总层数
对于(var i=0;i0){
newGroup=app.activeDocument.groupItems.add();
对于(z=0;z0){
//获取要将文件保存到的文件夹
var destFolder=null;
destFolder=Folder.selectDialog('Select Folder for Low Res PDF file.','~');
如果(destFolder!=null){
var选项,i,sourceDoc,targetFile;
//获取要使用的PDF选项
options=this.getOptions();
//您可以通过更改getOptions()函数中的代码来调整这些选项。
sourceDoc=app.activeDocument;//返回文档对象
//获取要将文档另存为pdf格式的文件
targetFile=this.getTargetFile(sourceDoc.name,'.pdf',destFolder);
//另存为pdf
sourceDoc.saveAs(targetFile,选项);
警报(“低分辨率PDF已保存”);
}
}
否则{
抛出新错误('没有打开的文档!');
}
}
捕获(e){
警报(如消息“脚本警报”,真);
}
/**返回要用于生成的文件的选项。
@返回PDFSaveOptions对象
*/
函数getOptions(){
var NamePreset=‘证明高分辨率PDF’;
//创建所需的选项对象
var options=新的PDFSaveOptions();
options.pDFPreset=“[最小文件大小]”;
返回选项;
}
/**返回要保存或导出文档的文件。
@param docName文档的名称
@param ext要应用的文件扩展名的扩展名
@param destFolder输出文件夹
@返回文件对象
*/
函数getTargetFile(docName、ext、destFolder){
var newName=“_HR”;
//如果名称没有点(因此没有扩展名),
//只需附加扩展名
if(docName.indexOf('.')<0){
newName=docName+ext;
}否则{
var dot=docName.lastIndexOf('.');
newName=docName.substring(0,点)+newName;
newName+=ext;
}
//创建要保存到的文件对象
var myFile=新文件(destFolder+'/'+newName);
//飞行前访问权
如果(myFile.open(“w”)){
myFile.close();
}
否则{
抛出新错误(“访问被拒绝”);
}
返回myFile;
}

Javascript区分大小写。我找到了你的
options.pDFPreset="[Smallest File Size]";
options.PDFPreset="[Smallest File Size]";