Font Packaging Script Error in InDesign
When ID packages the file, it is simply not possible to package the fonts all together.
A nice font packaging script that someone else shared for free.
But it prompts an error for some files.
Any god willing to help to fix it?
English translation in parentheses
Thanks a lot.
The ID version is the latest

//获取当前文档(Get the current document)
var doc = app.activeDocument;
//获取字体列表(Get the list of fonts)
var fonts = doc.fonts.everyItem().name;
//创建数组(Creating Arrays)
var fontFiles = [];
//循环字体并添加到数组中(Loop through the fonts and add to the array)
for (var i = 0; i < fonts.length; i++) {
var font = fonts[i];
var fontFile = File(doc.fonts.itemByName(font).location);
if (arrayContains(fontFiles, fontFile) == false) {
fontFiles.push(fontFile);
}
}
//创建打包文件夹(Creating a Packaging Folder)
var packageFolder = Folder(doc.filePath + "/Package");
if (!packageFolder.exists) {
packageFolder.create();
}
//将字体复制到打包文件夹(Copy the fonts to the packaging folder)
for (var i = 0; i < fontFiles.length; i++) {
var fontFile = fontFiles[i];
var newFile = File(packageFolder.fsName + "/" + fontFile.name);
fontFile.copy(newFile);
}
//打开打包文件夹(Open the packing folder)
packageFolder.execute();
function arrayContains(arr, item) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].toString() == item.toString()) {
return true;
}
}
return false;
}
<Title renamed by MOD>
