Extract font metadata information via JavaScript

Gain deeper understanding of your fonts with our JavaScript API. Read font metadata seamlessly for TTF, WOFF, WOFF2, and SVG, optimizing your design workflow.

 

TrueType font table ’name’ is storage for text strings related to that font. These strings can be written in different languages and can represent various entities, such as font names, family names, designer names, license info, copyright notices, and so on. In short, the lines that are held in the table ’name’ describe font metadata. For more details read the Working with ’name’ table article.

JavaScript 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 .

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, it displays the error message on the ‘output’ element

More details are in developer guide article Getting Metadata .

  var ffileFontGetInfo = function (e) {
    const file_reader = new FileReader();
    file_reader.onload = (event) => {
      const json = AsposeFontGetInfo(event.target.result, e.target.files[0].name);
      if (json.errorCode == 0) {
        document.getElementById('output').textContent = "Name records count: " + json.records.length;
        for (let recordIndex = 0; recordIndex < json.records.length; recordIndex++) 
			document.getElementById('output').textContent += " " + "\n"
                                                         + "NameId : " + json.records[recordIndex].NameId
                                                         + ";  PlatformId : " + json.records[recordIndex].PlatformId
                                                         + ";  PlatformSpecificId : " + json.records[recordIndex].PlatformSpecificId
                                                         + ";  LanguageId : " + json.records[recordIndex].LanguageId
                                                         + ";  Info : " + json.records[recordIndex].Info;
      }
      else document.getElementById('output').textContent = json.errorText;
    }
    file_reader.readAsArrayBuffer(e.target.files[0]);
  }

Add/Update TrueType or OpenType Font metadata information.

Just use the FontSetInfo . More details are in developer guide article Setting Metadata .

  var fFontSetInfo = function (e) {
    const file_reader = new FileReader();
    file_reader.onload = (event) => {

      const nameId = new Function("return Module.TtfNameTableNameId." + document.getElementById("NameId").value)();
      const platformId = Module.TtfNameTablePlatformId.Microsoft;
      const platformSpecificId = Module.TtfNameTableMSPlatformSpecificId.Unicode_BMP_UCS2.value;
      const langID = Module.TtfNameTableMSLanguageId.English_United_States.value;
      const text = document.getElementById("textValue").value;

      const json = AsposeFontSetInfo(blob, file.name, nameId, platformId, platformSpecificId, langID, text);
      if (json.errorCode == 0) {
        DownloadFile(json.fileNameResult);
        //DownloadFile(file.name);
      }
      else document.getElementById('output').textContent = json.errorText;
    }
    file_reader.readAsArrayBuffer(file);
  }

Also, the library support Web Worker mode to improve the responsive performance of the user interface on a web page. Visit our JavaScript documentation for more help to use. There you will find ready-made solutions for use in your projects.

To see this functionality realized in an actual cross-platform application go to Aspose Font Converter app . There you can also find many more API solutions to work with fonts and text.

Go to the Documentation for Javascript 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