[英]illustrator javascript export jpg spaces replaced by a dash
我寫了一個腳本將文件導出為 jpeg。 但是,在導出時,如果文件名包含空格,則這些空格將替換為破折號。 為什么? 如果您在手冊中從 Illustrator 導出,則文件名會正確顯示。 如果您使用 fileJpg.saveDlg('');,撥號窗口會正確顯示文件名,但會不斷用破折號替換空格。
function ExportJpgFunction(){
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileJpg = new File('D:\\for Jpg and Eps/' + myWindow.fnamePanel.fileNameText.text + '.jpg');
fileJpg.saveDlg('');
exportOptions.antiAliasing = true;
exportOptions.qualitySetting = 100;
exportOptions.verticalScale = 420;
exportOptions.horizontalScale = 420;
app.activeDocument.exportFile( fileJpg, type, exportOptions );
您可以使用簡單的解決方法,只需用破折號重命名文件,在代碼末尾添加以下行:
var fileJpg1 = new File("c:\\tmp\\for-Jpg-and-Eps.jpg");//path to file with dashes
fileJpg1.rename('for Jpg and Eps.jpg');
這是 Illustrator 腳本中的錯誤。 要刪除它,您必須手動替換。
正如其他人所指出的,這是 Adobe Illustrator 的一個錯誤/怪癖。
我通過在 Adobe Illustrator 創建它們后從文件名中刪除破折號來解決同樣的問題。
renameFile ('D:\\\\for Jpg and Eps/' + replaceSpacesWithDashes(myWindow.fnamePanel.fileNameText.text) + '.jpg', myWindow.fnamePanel.fileNameText.text + '.jpg'); function replaceSpacesWithDashes (stringToDash) { //Simulate dashed up files from undashed original var dashedString = stringToDash.replace(/\\s+/g, "-"); return dashedString; } function renameFile (fileFromPath, newName) { var b = new File(fileFromPath); b.rename(newName); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.