Indesign CS6 Scripting - Exporting images

前端 未结 2 1233
抹茶落季
抹茶落季 2021-01-03 15:57

I\'m having trouble writing a js script in indesign cs6 to export my formatted images. the code below (found on this website and slightly modified) only opens the document.<

2条回答
  •  醉酒成梦
    2021-01-03 16:46

    The file name isn't located on the rectangle but on the link related to the placed graphic. This should do what you want given an open document:

    test();
    
    
    
    function test() {
    
        var myDoc = app.activeDocument, apis = myDoc.allPageItems, rect, fileName;
    
    
        while ( rect = apis.pop() )
        {
            if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue; }
    
            fileName = File ( rect.graphics[0].itemLink.filePath ).name;
            fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );
    
            app.jpegExportPreferences.exportResolution = 300;
            app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
    
            //give it a unique name
            var myFile = new File (Folder.desktop+"/"+ fileName);
    
            rect.exportFile(ExportFormat.JPG, myFile);
        }
    }
    

提交回复
热议问题