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

Font Packaging Script Error in InDesign

Guide ,
Oct 21, 2024 Oct 21, 2024

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.jpgexpand image

 

 

 

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

 

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

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

 

Translate
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

Instead of arrayContains() function - you could use a string and then indexOf on this string - instead of iterating an array.

 

Translate
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
Guide ,
Oct 21, 2024 Oct 21, 2024

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

Translate
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

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?

 

Translate
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
Guide ,
Oct 21, 2024 Oct 21, 2024

New error message

996.jpgexpand image

Translate
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

@dublove

 

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

 

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

 

Translate
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

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.pngexpand image

Translate
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
Guide ,
Oct 22, 2024 Oct 22, 2024

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.jpegexpand image

 

Translate
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

@dublove

 

Please change:

 

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

 

To: 

 

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

 

Translate
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
Guide ,
Oct 22, 2024 Oct 22, 2024

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.jpgexpand image

Translate
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

If you check your document’s Find/Replace Font does the problem font have a valid Path listed under Info?

 

Screen Shot 1.pngexpand image

Translate
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
Guide ,
Oct 22, 2024 Oct 22, 2024

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.jpgexpand image

Translate
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

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.pngexpand image

 

 

Screen Shot 3.pngexpand image

Translate
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
Guide ,
Oct 22, 2024 Oct 22, 2024

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.

Translate
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

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

Translate
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
Guide ,
Dec 23, 2024 Dec 23, 2024

Yes, I found out today.
Some fonts won't pack.
It says it's illegal, I wonder why?

669.jpgexpand image

Translate
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 ,
Dec 23, 2024 Dec 23, 2024
quote

Yes, I found out today.
Some fonts won't pack.
It says it's illegal, I wonder why?

669.jpgexpand image


By dublove

 

It's called "copyright". 

 

Translate
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
Guide ,
Dec 23, 2024 Dec 23, 2024

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.

Translate
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 ,
Dec 23, 2024 Dec 23, 2024

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.

 

Translate
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
Guide ,
Apr 22, 2025 Apr 22, 2025
LATEST

@rob day  @Robert at ID-Tasker 

Fonts fail to pack, is it possible that the fonts are not installed to C:\windows\Fonts?
Instead, they were installed to this location:
C:\Users\UserName\AppData\Local\Microsoft\Windows\Fonts

Translate
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