Dear Aspose Support,
Our client encountered an issue where, after performing an XMP update, certain color profile namespaces are missing from the updated file’s XMP data. These missing namespaces are proprietary and do not belong to our client’s own XMP schema.
For your reference, I’ve attached the following files:
- OriginalFile.docx and UpdatedXMP.docx – text versions of the XMP before and after the update.
- MissingNamespaces.docx – a list of namespaces missing in the updated XMP. Take note that this was extracted from csv file so expect a different format but the important here is the namespace
MissingNamespaces.docx (15.0 KB)
UpdatedXMP.docx (17.4 KB)
OrignalFile.docx (19.1 KB)
OriginalFile.jpg (174.0 KB)
UpdatedXMP.jpg (165.4 KB)
- OriginalFile.jpg and UpdatedXMP.jpg – the image files from which the above XMP data was extracted.
Please review these attachments and advise on why the proprietary namespaces are being removed during the update.
Aspose.Imaging version 25.7.0
private void UpdateXmpMetadata(IUpdateXmpMetadataMediaAction action)
{
using (var inputStream = System.IO.File.OpenRead(action.Path))
using (var img = Image.Load(inputStream))
{
if ((_supportedTargetFormats.Contains(img.FileFormat) || Path.GetExtension(action.Path).ToLower() == ".jpg" || Path.GetExtension(action.Path).ToLower() == ".tif") && img is RasterImage && !String.IsNullOrEmpty(action.XmpMetadataMapping))
{
XDocument xmpMapping = XDocument.Parse(action.XmpMetadataMapping);
// Getting the xmp metadata
XmpPacketWrapper xmpData = ((RasterImage)img).XmpData;
if (xmpData == null)
{
// Create xmp metadata if the image doesn't contains any xmp data.
XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString());
XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
XmpMeta xmpMeta = new XmpMeta();
xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
((RasterImage)img).XmpData = xmpData;
}
foreach (var mapping in xmpMapping.Descendants("xmpMapping").Elements("add"))
{
// Get values from xmp metadata mapping
var xmpNamespace = mapping.Attribute("namespace").Value;
var xmpName = mapping.Attribute("name").Value;
var xmpPrefix = mapping.Attribute("prefix").Value;
var xmpValue = mapping.Value;
if (xmpData.ContainsPackage(xmpNamespace))
{
// Xmp namespace exists
foreach (var xmpPackage in xmpData.Packages)
{
if (xmpPackage.NamespaceUri.Trim().ToLower() == xmpNamespace.Trim())
{
if (xmpPackage.ContainsKey(xmpPackage.Prefix + ":" + xmpName))
{
// Update xmp value if the property exists
xmpPackage[(xmpPackage.Prefix + ":" + xmpName)] = xmpValue;
}
else
{
// Create new property if it not exists
xmpPackage.AddValue(xmpPackage.Prefix + ":" + xmpName, xmpValue);
}
}
}
}
else
{
// Create xmp namespace and xmp property if namespace not exists
XmpBasicPackage xmp = new XmpBasicPackage(xmpPrefix, xmpNamespace);
xmp.AddValue(xmpPrefix + ":" + xmpName, xmpValue);
xmpData.AddPackage(xmp);
}
}
}
using (var outputStream = new MemoryStream())
{
img.Save(outputStream);
using (var fileStream = System.IO.File.Create(action.OutputPath))
{
outputStream.Seek(0, System.IO.SeekOrigin.Begin);
outputStream.CopyTo(fileStream);
}
}
}
}```