Getting Metadata | API Solution for JavaScript
How to read the font metadata from ’name’ table?
You can read records from ’name’ table of TrueType or OpenType font using the AsposeFontGetInfo function.
The corresponding enumerations are used to indicate each value of record from array. The function returns names of these enumeraions.
So,
TtfNameTableNameId and
TtfNameTablePlatformId are used for nameId
and platformId
,
TtfNameTableMacPlatformSpecificId,
TtfNameTableMSPlatformSpecificId, or
TtfNameTableUnicodePlatformSpecificId for platformSpecificId
, and
TtfNameTableMacLanguageId, or
TtfNameTableMSLanguageId for languageId
values.
Examples of getting metadata
- Create a ‘FileReader’.
- Run the AsposeFontGetInfo function.
- Next, if the
json.errorCode
is 0, you can get the result data. If thejson.errorCode
parameter is not equal to 0 and, accordingly, there will be an error in your file, then information about such an error will be contained in thejson.errorText
. - Resulting json object contains
records
array. The each record contains fieldsNameId
,PlatformId
,PlatformSpecificId
,LanguageId
,Info
with information fromname
table of font.
1 var ffileFontGetInfo = function (e) {
2 const file_reader = new FileReader();
3 file_reader.onload = (event) => {
4 const json = AsposeFontGetInfo(event.target.result, e.target.files[0].name);
5 if (json.errorCode == 0) {
6 document.getElementById('output').textContent = "Name records count: " + json.records.length;
7 for (let recordIndex = 0; recordIndex < json.records.length; recordIndex++)
8 document.getElementById('output').textContent += " " + "\n"
9 + "NameId : " + json.records[recordIndex].NameId
10 + "; PlatformId : " + json.records[recordIndex].PlatformId
11 + "; PlatformSpecificId : " + json.records[recordIndex].PlatformSpecificId
12 + "; LanguageId : " + json.records[recordIndex].LanguageId
13 + "; Info : " + json.records[recordIndex].Info;
14 }
15 else document.getElementById('output').textContent = json.errorText;
16 }
17 file_reader.readAsArrayBuffer(e.target.files[0]);
18 }
or using Web Worker:
1<script type="text/javascript">
2
3 /*Create Web Worker*/
4 const AsposeFontWebWorker = new Worker("AsposeFontforJS.js");
5 AsposeFontWebWorker.onerror = evt => console.log(`Error from Web Worker: ${evt.message}`);
6 AsposeFontWebWorker.onmessage = evt => document.getElementById('output').textContent =
7 (evt.data == 'ready') ? 'loaded!' :
8 (evt.data.json.errorCode == 0) ? "Name records count: " + evt.data.json.records.length +
9 evt.data.json.records.reduce((ret, a) => ret +
10 "\nNameId : " + a.NameId
11 + "; PlatformId : " + a.PlatformId
12 + "; PlatformSpecificId : " + a.PlatformSpecificId
13 + "; LanguageId : " + a.LanguageId
14 + "; Info : " + a.Info,"") :
15 `Error: ${evt.data.json.errorText}`;
16
17 /*Event handler*/
18 var ffileFontGetInfo = function (e) {
19 const file_reader = new FileReader();
20 file_reader.onload = (event) => {
21 var transfer = [event.target.result];
22 var params = [event.target.result, e.target.files[0].name];
23 return AsposeFontWebWorker.postMessage({ "operation": "AsposeFontGetInfo", "params": params }, transfer);
24 }
25 file_reader.readAsArrayBuffer(e.target.files[0]);
26 }
27
28</script>
How to get the solution?
If you want to have the library, go to Aspose.Font for JavaScript product page. There you will find more opportunities that the solution gives you. You can download a free trial from or buy the product there.
If you have any troubles or questions left, feel free to post them at the Aspose.Font.Product Family section of the Free Support Forum and within a few hours our support team will clear everything up for you.
Also, check our Font Metadata cross-platform application to fully understand the functionality and the way API can be used for creating your own app.