Setting Metadata | API Solution for JavaScript
How to set the font metadata into ’name’ table?
You can add or change metadata information using the AsposeFontSetInfo function.
Parameter nameId
defines the logical string category for a record. Parameters platformId
, platformSpecificId
, and languageId
are used to set the language of the string. And the last parameter text
is used to set string data for a record.
If the record coincides with the added one by parameters platformID
, platformSpecificID
, languageID
, and nameID
already exists, the method doesn’t add a new record, but updates string data in the existing record using the value, defined by parameter text
.
Examples of setting metadata
- Create a ‘FileReader’.
- Define parameters and run the AsposeFontSetInfo function.
Use enum
TtfNameTableNameId and
TtfNameTablePlatformIdfor nameId
and platformId
,
TtfNameTableMacPlatformSpecificId,
TtfNameTableMSPlatformSpecificId, or
TtfNameTableUnicodePlatformSpecificId for platformSpecificId
, and
TtfNameTableMacLanguageId, or
TtfNameTableMSLanguageId for languageId
parameters.
- Next, if the
json.errorCode
is 0, then you can get 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
fileNameResult
field with file name of saved font in memory file system. Use DownloadFile function to get it.
1 var fFontSetInfo = function (e) {
2 const file_reader = new FileReader();
3 file_reader.onload = (event) => {
4
5 const nameId = new Function("return Module.TtfNameTableNameId." + document.getElementById("NameId").value)();
6 const platformId = Module.TtfNameTablePlatformId.Microsoft;
7 const platformSpecificId = Module.TtfNameTableMSPlatformSpecificId.Unicode_BMP_UCS2.value;
8 const text = document.getElementById("textValue").value;
9 const langID = 1033;
10
11 const json = AsposeFontSetInfo(blob, file.name, nameId, platformId, platformSpecificId, langID, text);
12 if (json.errorCode == 0) {
13 DownloadFile(json.fileNameResult);
14 //DownloadFile(file.name);
15 }
16 else document.getElementById('output').textContent = json.errorText;
17 }
18 file_reader.readAsArrayBuffer(file);
or using Web Worker:
1<script type="text/javascript">
2 /*Create Web Worker*/
3 const AsposeFontWebWorker = new Worker("AsposeFontforJS.js");
4 AsposeFontWebWorker.onerror = (evt) => console.log(`Error from Web Worker: ${evt.message}`);
5 AsposeFontWebWorker.onmessage = (evt) => document.getElementById("output").textContent =
6 (evt.data == 'ready') ? 'library loaded!' :
7 (evt.data.json.errorCode == 0) ? `Result:\n${DownloadFile(evt.data.json.fileNameResult, "font/ttf", evt.data.params[0])}` : `Error: ${evt.data.json.errorText}`;
8
9 /*Event handler*/
10 const ffileFontSetInfo = e => {
11 const file_reader = new FileReader();
12 file_reader.onload = event => {
13 const nameId = 'Module.TtfNameTableNameId.' + document.getElementById("NameId").value;
14 //Value will be changed for PlatformId = PlatformId.Microsoft, PlatformSpecificId = MSPlatformSpecificId.Unicode_BMP_UCS2 (1) and languageID = 1033 (English_United_States = 0x0409)
15 const platformId = 'Module.TtfNameTablePlatformId.Microsoft';
16 const platformSpecificId = 'Module.TtfNameTableMSPlatformSpecificId.Unicode_BMP_UCS2';
17 const langID = 'Module.TtfNameTableMSLanguageId.English_United_States';
18 const text = document.getElementById("textValue").value;
19 transfer = [event.target.result];
20 params = [event.target.result, e.target.files[0].name, nameId, platformId, platformSpecificId, langID, text];
21 AsposeFontWebWorker.postMessage({ "operation": 'AsposeFontSetInfo', "params": params }, transfer);
22 };
23 file_reader.readAsArrayBuffer(e.target.files[0]);
24 };
25</script>
How to get the solution?
If you are interested in getting 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.