• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Font Packaging Script Error in InDesign

Advocate ,
Oct 21, 2024 Oct 21, 2024

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

999.jpg

 

 

 

//获取当前文档(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>

TOPICS
How to , Import and export , Performance , Scripting

Views

512

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 21, 2024 Oct 21, 2024

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. 

 

...

Votes

Translate

Translate
Community Expert ,
Oct 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

Add alert() to display "doc.fonts.itemByName(font).location" to see what is the problem.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

I don't know how to script. I got this off the internet.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024

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?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

New error message

996.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

@dublove

 

There should be ";" after alert(), sorry.

 

And as @rob day clarified - that's what I was suspecting - missing fonts and Adobe Fonts.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024

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;
}

 

 

Screen Shot 8.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 22, 2024 Oct 22, 2024

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

dublove_0-1729605348323.jpeg

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2024 Oct 22, 2024

Copy link to clipboard

Copied

@dublove

 

Please change:

 

alert("The Font " + doc.fonts.itemByName(font).name +" is not available")

 

To: 

 

alert("The Font " + font +" is not available")

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 22, 2024 Oct 22, 2024

Copy link to clipboard

Copied

No more errors, 

Two extra Unknowns?
These two fonts are not recognized. So far I've only encountered these two fonts
Rope Sequence Number HT (TT)
Rope Sequence Number ST (TT)

 

Thank you very much.
I'll just use it.

556.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2024 Oct 22, 2024

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?

 

Screen Shot 1.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 22, 2024 Oct 22, 2024

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

 

969.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2024 Oct 22, 2024

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.

 

Screen Shot 6.png

 

 

Screen Shot 3.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 22, 2024 Oct 22, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2024 Oct 22, 2024

Copy link to clipboard

Copied

LATEST

I installed the fonts you provided in my system before opening the IDML.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines