[Illustrator] 複数の ai ファイルをまとめて PDF や PNG で保存する
フォルダー内の ai ファイルなどを一括で PDF や PNG に変換して保存する方法です。
今回はスクリプトを使います。スクリプトを使わず、Bridge を使う方法もあります。
スクリプトの実行
PDF の場合は、「Save as PDFs.jsx」というスクリプトが、Illustrator のインストールフォルダー以下の「Scripting\Sample Scripts\JavaScript\Miscellaneous」フォルダーにあります。
Illustrator のメニュー[ファイル]-[スクリプト]-[その他のスクリプト]から、スクリプトファイルを開き実行します。
実行すると、次の手順で変換して保存できます。
- PDF ファイルで保存したい ai ファイルのあるフォルダーを選択
- ファイル名の指定(すべての ai ファイルの場合は「*.ai」と指定)
- 変換後の PDF ファイルを保存するフォルダーの選択
PNG 変換のスクリプト
PDF のスクリプトをもとに PNG で保存するようにしたスクリプトです。jsx ファイルとして保存して使ってください。スクリプト中の opts.horizontalScale = 100.0;
と opts.verticalScale = 100.0;
を変更すれば、拡大・縮小した画像を保存できます。
/********************************************************** | |
Save as PNGs.jsx | |
DESCRIPTION | |
This sample gets files specified by the user from the | |
selected folder and batch processes them and saves them | |
as PNGs in the user desired destination with the same | |
file name. | |
**********************************************************/ | |
// Main Code [Execution of script begins here] | |
// uncomment to suppress Illustrator warning dialogs | |
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; | |
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile; | |
// Select the source folder. | |
sourceFolder = Folder.selectDialog('Select the folder with Illustrator files you want to convert to PNG', '~'); | |
// If a valid folder is selected | |
if (sourceFolder != null) { | |
files = new Array(); | |
fileType = prompt('Select type of Illustrator files to you want to process. Eg: *.ai', ' '); | |
// Get all files matching the pattern | |
files = sourceFolder.getFiles(fileType); | |
if (files.length > 0) { | |
// Get the destination to save the files | |
destFolder = Folder.selectDialog('Select the folder where you want to save the converted PNG files.', '~'); | |
for (i = 0; i < files.length; i++) { | |
sourceDoc = app.open(files[i]); // returns the document object | |
// Call function getNewName to get the name and file to save the PNG | |
targetFile = getNewName(); | |
// Export as PNG | |
sourceDoc.exportFile(targetFile, ExportType.PNG24, getPNGOptions()); | |
sourceDoc.close(SaveOptions.DONOTSAVECHANGES); | |
} | |
alert('Files are saved as PNG in ' + destFolder); | |
} | |
else { | |
alert('No matching files found'); | |
} | |
} | |
/********************************************************* | |
getNewName: Function to get the new file name. The primary | |
name is the same as the source file. | |
**********************************************************/ | |
function getNewName() { | |
var ext, docName, newName, saveInFile, docName; | |
docName = sourceDoc.name; | |
ext = '.png'; // new extension for file | |
newName = ""; | |
for (var i = 0; docName[i] != "."; i++) { | |
newName += docName[i]; | |
} | |
newName += ext; // full name of the file | |
// Create a file object to save the png | |
saveInFile = new File(destFolder + '/' + newName); | |
return saveInFile; | |
} | |
/********************************************************* | |
getPNGOptions: Function to set the PNG saving options of the | |
files using the ExportOptionsPNG24 object. | |
**********************************************************/ | |
function getPNGOptions() { | |
// Create the ExportOptionsPNG24 object to set the PNG options | |
var opts = new ExportOptionsPNG24(); | |
// Setting ExportOptionsPNG24 properties. Please see the JavaScript Reference | |
// for a description of these properties. | |
// Add more properties here if you like | |
opts.antiAliasing = true; | |
opts.artBoardClipping = true; | |
opts.horizontalScale = 100.0; | |
opts.saveAsHTML = false; | |
opts.transparency = true; | |
opts.verticalScale = 100.0; | |
return opts; | |
} |