Extract font metadata information via Node.js
Seamlessly get font metadata of TTF, WOFF, WOFF2, and SVGfonts, improving your design workflow. Have a better understanding of your fonts with our Node.js API.
Have you ever wondered how fonts store information about themselves? Look no further than the TrueType ’name’ table! This hidden treasure trove holds a wealth of text strings in different languages, revealing various details about the font itself. Think of it as the font’s identification card. Here’s what you can find inside:
- Font Names: The official title and any alternative names the font might have.
- Family Names: Grouping fonts that share a similar design style.
- Designer Names: Recognizing the creative minds behind the font.
- Licensing and Copyright Information: Understanding usage rights and legal details.
Node.js font API can easily get metadata information from fonts such as OpenType and TrueType collections. It provides simple functions for these goals such as AsposeFontGetInfo and AsposeFontSetInfo .
🌟 Say goodbye to processing identifier values! Information is provided in a form understandable to humans through the names of used enumerations TtfNameTable::NameId , TtfNameTable::PlatformId , TtfNameTableMacPlatformSpecificId , TtfNameTableMSPlatformSpecificId , TtfNameTableUnicodePlatformSpecificId , TtfNameTableMacLanguageId , TtfNameTableMSLanguageId .
For more details read the Working with ’name’ table article. This resource delves deeper into its structure and details to empower you with a complete understanding.
How to read TrueType Font metadata information.
This code defines a function that is triggered when a file input element changes. Here’s what it does:
It creates a new FileReader object to read the contents of the uploaded file.
When the file is loaded (onload event), it calls a function AsposeFontGetInfo with the file’s content and name to extract font metadata.
If the extraction is successful (no error code), it displays the name records count on an HTML element with the id ‘output’, and then iterates over each name record, displaying its details such as NameId, PlatformId, PlatformSpecificId, LanguageId, and Info.
If there’s an error during the extraction, you will get the error message on the ‘output’ element displayed.
For more details go to the developer guide article Getting Metadata .
Node.js code example getting 'name' table information
const AsposeFont = require('asposefontnodejs');
const font_file = "./fonts/Lora-Regular.ttf";
AsposeFont().then(AsposeFontModule => {
//AsposeGetInfo - Get metadata info from font
json = AsposeFontModule.AsposeFontGetInfo(font_file);
console.log("AsposeFontGetInfo => %O", json.errorCode == 0 ? json.records.reduce((ret, a) => ret +
"\nNameId : " + a.NameId
+ "; PlatformId : " + a.PlatformId
+ "; PlatformSpecificId : " + a.PlatformSpecificId
+ "; LanguageId : " + a.LanguageId
+ "; Info : " + a.Info,"") : json.errorText);
});
Add/Update TrueType or OpenType Font metadata information.
Just use the FontSetInfo . More details are in developer guide article Setting Metadata .
Node.js code example for adding/updating font metadata
const AsposeFont = require('asposefontnodejs');
const font_file = "./fonts/Lora-Regular.ttf";
AsposeFont().then(AsposeFontModule => {
//AsposeSetInfo - set metadata info into font
const nameId = AsposeFontModule.TtfNameTableNameId.Description;
const platformId = AsposeFontModule.TtfNameTablePlatformId.Microsoft;
const platformSpecificId = AsposeFontModule.TtfNameTableMSPlatformSpecificId.Unicode_BMP_UCS2.value;
const langID = Module.TtfNameTableMSLanguageId.English_United_States.value;
const text = "Updated description";
const json = AsposeFontSetInfo(font_file, nameId, platformId, platformSpecificId, langID, text);
console.log("AsposeFontSetInfo => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
});
Also, the library support Web Worker mode to improve the responsive performance of the user interface on a web page. Visit our Node.js documentation for more help to use. There you will find ready-made solutions for use in your projects.
To see actual cross-platform applications developed with the use of this functionality go to Aspose.Font Metadata app . There you can also find many more API solutions to work with fonts and text.
Go to the Documentation for Node.js to get all the needed information to start working with the solution: Release Notes, Developer Guide, or Documentation for .NET - the Tutorials for the main features or the set of articles to teach you about font and other useful things.
Support and Learning Resources
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Release Notes
- Why Aspose.Font for C++?
- Customers List
- Success Stories