Add named value in XMP metadata of EPS | JavaScript
To add a named value in the XMP metadata of an EPS file, it is necessary to do several steps:
- Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’.
- On load event handler call AsposeXMPAddNamedValue and pass the file content, its name, and the result file name to it.
- The result JSON contains the file name in fileNameResult.
- You can download files by using the DownloadFile function: ‘DownloadFile(JSON.fileNameResult, “image/pdf”);’ and display the result ‘document.getElementById(‘output’).textContent = JSON.XMP;’
The next code snippet shows how to add named value in XMP metadata in the EPS file using JavaScript:
1 var fXMPAddNamedValue = function (e) {
2 const file_reader = new FileReader();
3 file_reader.onload = (event) => {
4 const input = [
5 ["xmpTPg:MaxPageSize", [["stDim:newKey", "NewValue"],["stDim:newKey2", "NewValue2"]] ],
6 ["xmpTPg:SwatchGroups", [["xmpG:newKey", "NewValue"]] ]
7 ];
8 const JSON = AsposeXMPAddNamedValue(event.target.result, e.target.files[0].name, e.target.files[0].name + "_out.eps", input);
9 if (JSON.errorCode == 0) {
10 DownloadFile(JSON.fileNameResult, "image/eps");
11 }
12 else
13 document.getElementById('output').textContent = JSON.errorText;
14 }
15 file_reader.readAsArrayBuffer(e.target.files[0]);
16 }
You can download examples and data files from GitHub.