GroupDocsGists
10/19/2017 - 11:37 AM

UpdateXMPPropertiesPngImage.cs

// For complete examples and data files, please go to https://github.com/groupdocsmetadata/GroupDocs_Metadata_NET
// initialize PngFormat
PngFormat pngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

// get xmp wrapper
XmpPacketWrapper xmpPacket = pngFormat.GetXmpData();

// create xmp wrapper if not exists
if (xmpPacket == null)
{
    xmpPacket = new XmpPacketWrapper();
}

// check if DublinCore schema exists
if (!xmpPacket.ContainsPackage(Namespaces.DublinCore))
{
    // if not - add DublinCore schema
    xmpPacket.AddPackage(new DublinCorePackage());
}

// get DublinCore package
DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore);

string authorName = "New author";
string description = "New description";
string subject = "New subject";
string publisher = "New publisher";
string title = "New title";

// set author
dublinCorePackage.SetAuthor(authorName);
// set description
dublinCorePackage.SetDescription(description);
// set subject
dublinCorePackage.SetSubject(subject);
// set publisher
dublinCorePackage.SetPublisher(publisher);
// set title
dublinCorePackage.SetTitle(title);
// update XMP package
pngFormat.SetXmpData(xmpPacket);

// commit changes
pngFormat.Save(Common.MapDestinationFilePath(filePath));