Hello,
I’m working on an InDesign plugin using UXP, and I’m running into an issue with loading a specific font. When I attempt to load it, I get the following error:
Error: The requested font family is not available.
However, I’ve found a workaround—if I set the desired font as the default font within the app before launching the plugin, it loads successfully without any errors.
Has anyone encountered this issue or found a more efficient solution?
Here is some of my code:
function getOrCreateStyle(name, styleGroupName, styleProperties) {
let paragraphStyle = thisDocument.paragraphStyles.itemByName(name);
if (!paragraphStyle.isValid) {
console.log(`Creating paragraph style "${name}" because it doesn't exist`);
let styleGroup = getOrCreateStyleGroup(styleGroupName);
if (styleGroup.isValid) {
let styleName = thisDocument.paragraphStyleGroups.itemByName(styleGroupName).paragraphStyles.itemByName(name);
if (!styleName.isValid) {
paragraphStyle = thisDocument.paragraphStyleGroups.itemByName(styleGroupName).paragraphStyles.add({
name: styleProperties.name,
appliedFont: styleProperties.appliedFont,
fontStyle: styleProperties.fontStyle,
pointSize: styleProperties.pointSize,
leading: styleProperties.leading,
tracking: styleProperties.tracking,
spaceAfter: styleProperties.spaceAfter,
spaceBefore: styleProperties.spaceBefore,
justification: styleProperties.justification,
fillColor: getCreateOrModifyColor(styleProperties.fillColor.name, styleProperties.fillColor.colorValue),
});
}
return styleName;
}
} else {
return paragraphStyle;
}
}
let SubheadlineParagraphStyleProperties = {
name:"Subheadline",
appliedFont:"Avenir LT Std",
fontStyle:"85 Heavy",
justification: Justification.LEFT_ALIGN,
pointSize:12,
leading:17,
tracking:20,
spaceAfter:0,
spaceBefore:0,
fillColor: {
name: "Gray",
colorValue: [62,53,48,19]
}
}
try {
subHeadlineTextbox.paragraphs.item(1).appliedParagraphStyle = getCreateOrModifyStyle("Subheadline", "Sub Styles", SubheadlineParagraphStyleProperties);
} catch (error) {
console.log('Error: ', error);
}