Copy link to clipboard
Copied
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>
Replace this part of you script with my version:
//循环字体并添加到数组中(Loop through the fonts and add to the array)
for (var i = 0; i < fonts.length; i++) {
var font = fonts[i];
alert(doc.fonts.itemByName(font).location);
var fontFile = File(doc.fonts.itemByName(font).location);
if (arrayContains(fontFiles, fontFile) == false) {
fontFiles.push(fontFile);
}
}
You'll get a message for each font - take a screenshot for one before error message - and post it here.
...
Copy link to clipboard
Copied
Add alert() to display "doc.fonts.itemByName(font).location" to see what is the problem.
Copy link to clipboard
Copied
Instead of arrayContains() function - you could use a string and then indexOf on this string - instead of iterating an array.
Copy link to clipboard
Copied
I don't know how to script. I got this off the internet.
Copy link to clipboard
Copied
Replace this part of you script with my version:
//循环字体并添加到数组中(Loop through the fonts and add to the array)
for (var i = 0; i < fonts.length; i++) {
var font = fonts[i];
alert(doc.fonts.itemByName(font).location);
var fontFile = File(doc.fonts.itemByName(font).location);
if (arrayContains(fontFiles, fontFile) == false) {
fontFiles.push(fontFile);
}
}
You'll get a message for each font - take a screenshot for one before error message - and post it here.
@rob day - can you maybe make a better version using try...catch?
Copy link to clipboard
Copied
New error message
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi @dublove , I get your error if the font is missing, also any fonts activated from Adobe Fonts do not have an accessible location, so they will not copy.
You could catch a missing font and display an alert, but this would not handle Adobe Type fonts, which can not be packaged or copied:
//获取当前文档(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];
try {
var fontFile = File(doc.fonts.itemByName(font).location);
if (arrayContains(fontFiles, fontFile) == false) {
fontFiles.push(fontFile);
}
}catch(e) {
alert("The Font " + doc.fonts.itemByName(font).name +" is not available")
}
}
//创建打包文件夹(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;
}
Copy link to clipboard
Copied
Hi @rob day
Thank you very muck.
I'm not missing fonts and I'm not using Adobe's online fonts.
Added the ; sign as well, but it still prompts an error
Copy link to clipboard
Copied
Please change:
alert("The Font " + doc.fonts.itemByName(font).name +" is not available")
To:
alert("The Font " + font +" is not available")
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If you check your document’s Find/Replace Font does the problem font have a valid Path listed under Info?
Copy link to clipboard
Copied
No, it's not, it's pointing to the path:
Packaged Document fonts directory.
There is a secondary packaging issue involved here.
Sometimes you just copy to another directory, and chances are the font path will still point to the "Document fonts" directory from the first packaging.
I went through two packages and it pointed to the "Document fonts" directory in the current directory.
But it still doesn't pack both fonts.
The problem with "the secondary packaging" might solve the problem I mentioned a while back: messed up fonts
Copy link to clipboard
Copied
If I install the fonts you attached in the OSX user Fonts folder, InDesign does not load them, and when I open your IDML they are listed as missing.
Copy link to clipboard
Copied
IDML is of course missing fonts as it is not a packaged file and there are no current Document Fonts.
I'm just providing the reference.
Copy link to clipboard
Copied
I installed the fonts you provided in my system before opening the IDML.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Yes, I found out today.
Some fonts won't pack.
It says it's illegal, I wonder why?
By @dublove
It's called "copyright".
Copy link to clipboard
Copied
It doesn't seem to be all that.
Though the font is copyrighted as “editable, readable, and writable.”
but the copyright of another Chinese font is “Installable”, but it can't be packaged either.
Copy link to clipboard
Copied
Yes, becuase if font is "not redistributable" - Adobe won't pack it - person that you'll send your package to - should have this font already.