The Extensible Metadata Platform (XMP) is an XML-based ISO metadata standard, originally created by Adobe Systems Inc. It defines a data structure, serialization model and basic metadata properties intended to form a unified metadata package that can be embedded into different media formats. The defined XMP data model can be used to store any set of metadata properties. These can be simple name/value pairs, structured values or lists of values. The data can be nested as well.
To access XMP metadata in a file of any supported format, GroupDocs.Metadata provides the IXmp.getXmpPackage method. The following are the steps to read XMP metadata:
GroupDocs.Metadata also provides an API allowing users to work with fully custom XMP schemes/packages. Please refer to this code snippet to learn more.
Updating XMP properties
The GroupDocs.Metadata API facilitates the user to update XMP metadata in a convenient way - using the XmpPacketWrapper class methods. Follow the below steps to update XMP metadata in a file of any supported format.
try(Metadatametadata=newMetadata(Constants.GifWithXmp)){IXmproot=(IXmp)metadata.getRootPackage();if(root.getXmpPackage()!=null){// if there is no such scheme in the XMP package we should create itif(root.getXmpPackage().getSchemes().getDublinCore()==null){root.getXmpPackage().getSchemes().setDublinCore(newXmpDublinCorePackage());}root.getXmpPackage().getSchemes().getDublinCore().setFormat("image/gif");root.getXmpPackage().getSchemes().getDublinCore().setRights("Copyright (C) 2011-2020 GroupDocs. All Rights Reserved");root.getXmpPackage().getSchemes().getDublinCore().setSubject("test");if(root.getXmpPackage().getSchemes().getCameraRaw()==null){root.getXmpPackage().getSchemes().setCameraRaw(newXmpCameraRawPackage());}root.getXmpPackage().getSchemes().getCameraRaw().setShadows(50);root.getXmpPackage().getSchemes().getCameraRaw().setAutoBrightness(true);root.getXmpPackage().getSchemes().getCameraRaw().setAutoExposure(true);root.getXmpPackage().getSchemes().getCameraRaw().setCameraProfile("test");root.getXmpPackage().getSchemes().getCameraRaw().setExposure(0.0001);// If you don't want to keep the old values just replace the whole schemeroot.getXmpPackage().getSchemes().setXmpBasic(newXmpBasicPackage());root.getXmpPackage().getSchemes().getXmpBasic().setCreateDate(newDate());root.getXmpPackage().getSchemes().getXmpBasic().setBaseUrl("https://groupdocs.com");root.getXmpPackage().getSchemes().getXmpBasic().setRating(5);root.getXmpPackage().getSchemes().setBasicJobTicket(newXmpBasicJobTicketPackage());// Set a complex type propertyXmpJobjob=newXmpJob();job.setID("1");job.setName("test job");job.setUrl("https://groupdocs.com");root.getXmpPackage().getSchemes().getBasicJobTicket().setJobs(newXmpJob[]{job});// ...metadata.save(Constants.OutputGif);}}
Adding a custom XMP package
The GroupDocs.Metadata API provides access to a number of commonly used XMP schemes. But it also allows you to create fully custom XMP packages containing user-defined properties. The example below demonstrates how to create and add a custom XMP package to a file.
try(Metadatametadata=newMetadata(Constants.InputJpeg)){IXmproot=(IXmp)metadata.getRootPackage();XmpPacketWrapperpacket=newXmpPacketWrapper();XmpPackagecustom=newXmpPackage("gd","https://groupdocs.com");custom.set("gd:Copyright","Copyright (C) 2011-2020 GroupDocs. All Rights Reserved.");custom.set("gd:CreationDate",newDate());custom.set("gd:Company",XmpArray.from(newString[]{"Aspose","GroupDocs"},XmpArrayType.Ordered));packet.addPackage(custom);root.setXmpPackage(packet);metadata.save(Constants.OutputJpeg);}
Removing XMP metadata
To remove the XMP package from a file just pass null to the IXmp.setXmpPackage method as a parameter. The code sample below shows how to remove XMP metadata from a file.