public void UpdateXMPData() { try { //ExStart:UpdateXMP // path to the modified file string filePath = "Images/Jpeg/sample.jpg"; // get xmp wrapper XmpPacketWrapper xmpWrapper = MetadataUtility.ExtractXmpPackage(filePath); // if wrapper is null if (xmpWrapper == null) { // create it xmpWrapper = new XmpPacketWrapper(); } // create package XmpPackage addingSchema = new XmpPackage("rs", "http://www.metadataworkinggroup.com/schemas/regions/"); // set date property addingSchema.AddValue("rs:createdDate", DateTime.UtcNow); // set string property addingSchema.AddValue("rs:File", "File name"); //initialze unordered xmp array XmpArray managersArray = new XmpArray(XmpArrayType.UNORDERED); managersArray.AddItem("Joe Doe"); managersArray.AddItem("Adam White"); // set array property addingSchema.SetArray("rs:managers", managersArray); // initialize xmp language alternative LangAlt availableDays = new LangAlt(); // add first value for 'en-us' language availableDays.AddLanguage("en-us", "Tue"); // add second value for 'en-us' languge availableDays.AddLanguage("en-us", "Fri"); // set LangAlt property addingSchema.SetLangAlt("rs:days", availableDays); // update xmp wrapper with new schema xmpWrapper.AddPackage(addingSchema); // create XmpMetadata with updated wrapper XmpMetadata xmpMetadata = new XmpMetadata(); xmpMetadata.XmpPacket = xmpWrapper; // update XMP MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //ExEnd:UpdateXMP } catch (Exception exp) { } }
/// <summary> /// Shows how to read, update and remove XMP metadata in AVI format /// Feature is supported in version 17.06 or greater /// </summary> public static void DealWithXmpMetaData() { //ExStart:DealWithXmpMetaData // initialize AviFormat using (AviFormat aviFormat = new AviFormat(Common.MapSourceFilePath(filePath))) { // get XMP var xmpMetadata = aviFormat.GetXmpData(); // create XMP if absent if (xmpMetadata == null) { xmpMetadata = new XmpPacketWrapper(); } // setup properties xmpMetadata.Schemes.DublinCore.Format = "avi"; xmpMetadata.Schemes.XmpBasic.CreateDate = DateTime.UtcNow; xmpMetadata.Schemes.XmpBasic.CreatorTool = "GroupDocs.Metadata"; // update xmp aviFormat.SetXmpData(xmpMetadata); // and commit changes aviFormat.Save(); } //ExEnd:DealWithXmpMetaData }
/// <summary> /// Updates XMP data of Gif file and creates output file /// </summary> public static void UpdateXMPProperties() { try { //ExStart:UpdateXMPPropertiesGifImage // initialize GifFormat GifFormat gifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); if (gifFormat.IsSupportedXmp) { // get xmp wrapper XmpPacketWrapper xmpPacket = gifFormat.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 gifFormat.SetXmpData(xmpPacket); // commit changes gifFormat.Save(Common.MapDestinationFilePath(filePath)); } //ExEnd:UpdateXMPPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates XMP data of Jpeg file and creates output file /// </summary> public static void UpdateXMPProperties() { try { //ExStart:UpdateXmpPropertiesJpegImage // initialize JpegFormat JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath)); // get xmp wrapper XmpPacketWrapper xmpPacket = jpegFormat.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 jpegFormat.SetXmpData(xmpPacket); // commit changes jpegFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateXmpPropertiesJpegImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
private List <PropertyItem> AppendXMPData(XmpPacketWrapper xmpMetadata, List <PropertyItem> values) { if (xmpMetadata != null) { PropertyItem propertyItem; foreach (XmpPackage package in xmpMetadata.Packages) { foreach (KeyValuePair <string, XmpValueBase> pair in package) { XmpArray xmpArray = pair.Value as XmpArray; LangAlt langAlt = pair.Value as LangAlt; XmpComplexType xmpComplex = pair.Value as XmpComplexType; if (xmpArray != null) { propertyItem = new PropertyItem(pair.Key, pair.Key, false); if (!values.Contains(propertyItem)) { values.Add(propertyItem); } foreach (string arrayItem in xmpArray.Values) { propertyItem = new PropertyItem(arrayItem, arrayItem, false); if (!values.Contains(propertyItem)) { values.Add(propertyItem); } } } else if (langAlt != null) { propertyItem = new PropertyItem(pair.Key + langAlt.ToString(), langAlt.ToString(), false); if (!values.Contains(propertyItem)) { values.Add(propertyItem); } } else { propertyItem = new PropertyItem(pair.Key, pair.Value.ToString(), false); if (!values.Contains(propertyItem)) { values.Add(propertyItem); } } } } } return(values); }
public void LoadControl(XmpPacketWrapper xmpMetadata) { treeView1.Nodes.Clear(); if (xmpMetadata != null) { foreach (XmpPackage package in xmpMetadata.Packages) { treeView1.Nodes.Add(package.NamespaceUri, package.NamespaceUri); TreeNode treePackage = treeView1.Nodes[package.NamespaceUri]; foreach (KeyValuePair<string, XmpValueBase> pair in package) { XmpArray xmpArray = pair.Value as XmpArray; LangAlt langAlt = pair.Value as LangAlt; XmpComplexType xmpComplex = pair.Value as XmpComplexType; if (xmpArray != null) { treePackage.Nodes.Add(pair.Key, pair.Key); foreach (string arrayItem in xmpArray.Values) { treePackage.Nodes[pair.Key].Nodes.Add(arrayItem, arrayItem); } } else if (langAlt != null) { treePackage.Nodes.Add(pair.Key, pair.Key); treePackage.Nodes[pair.Key].Nodes.Add(pair.Key + langAlt.ToString(), langAlt.ToString()); } else { string xmpProperty = string.Format("{0} - {1}", pair.Key, pair.Value.ToString()); treePackage.Nodes.Add(pair.Key, xmpProperty); } } } } treeView1.ExpandAll(); }
public void LoadControl(XmpPacketWrapper xmpMetadata) { treeView1.Nodes.Clear(); if (xmpMetadata != null) { foreach (XmpPackage package in xmpMetadata.Packages) { treeView1.Nodes.Add(package.NamespaceUri, package.NamespaceUri); TreeNode treePackage = treeView1.Nodes[package.NamespaceUri]; foreach (KeyValuePair <string, XmpValueBase> pair in package) { XmpArray xmpArray = pair.Value as XmpArray; LangAlt langAlt = pair.Value as LangAlt; XmpComplexType xmpComplex = pair.Value as XmpComplexType; if (xmpArray != null) { treePackage.Nodes.Add(pair.Key, pair.Key); foreach (string arrayItem in xmpArray.Values) { treePackage.Nodes[pair.Key].Nodes.Add(arrayItem, arrayItem); } } else if (langAlt != null) { treePackage.Nodes.Add(pair.Key, pair.Key); treePackage.Nodes[pair.Key].Nodes.Add(pair.Key + langAlt.ToString(), langAlt.ToString()); } else { string xmpProperty = string.Format("{0} - {1}", pair.Key, pair.Value.ToString()); treePackage.Nodes.Add(pair.Key, xmpProperty); } } } } treeView1.ExpandAll(); }
public void GetXMPData() { try { //ExStart:GetXMPData // create new instance of GifFormat GifFormat gif = new GifFormat(@"C:\sample.gif"); // old version of gif format does not support xmp if (!gif.IsSupportedXmp) { return; } // get XMP data XmpPacketWrapper xmp = gif.GetXmpData(); //ExEnd:GetXMPData } catch (Exception exp) { } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { tabMetadataTypes.TabPages.Clear(); DataSet ds; using (StreamReader streamReader = new StreamReader(openFileDialog.FileName)) { try { ds = ExportFacade.ExportToDataSet(streamReader.BaseStream); } catch (GroupDocs.Metadata.Exceptions.InvalidFormatException) { MessageBox.Show(@"This format is not supported"); return; } catch (GroupDocs.Metadata.Exceptions.GroupDocsException ex) { MessageBox.Show(string.Format("Error: {0}", ex.Message)); return; } } propertiesEditor = null; saveMetadata.FileName = openFileDialog.FileName; if (ds.Tables.Count == 0) { MessageBox.Show(@"Metadata not found"); } else { for (int i = 0; i < ds.Tables.Count; i++) { DataTable table = ds.Tables[i]; Control child; string tabName; switch (table.TableName.ToLower()) { case "xmp": tabName = "XMP metadata"; XmpPacketWrapper xmpPacket = MetadataUtility.ExtractXmpPackage(openFileDialog.FileName); ucXmpTree xmpTree = new ucXmpTree(); xmpTree.LoadControl(xmpPacket); ResizeControl(xmpTree); child = xmpTree; break; case "pdf": case "doc": case "xls": case "ppt": tabName = "Document properties"; MetadataPropertyCollection properties = MetadataUtility.ExtractDocumentProperties(openFileDialog.FileName); propertiesEditor = new ucPropertiesEditor(); ResizeControl(propertiesEditor); propertiesEditor.LoadControl(properties); child = propertiesEditor; break; default: tabName = string.Format("{0} metadata", table.TableName); DataGridView gridView = new DataGridView(); ResizeControl(gridView); gridView.DataSource = table; child = gridView; break; } tabMetadataTypes.TabPages.Add(tabName); TabPage addedTab = tabMetadataTypes.TabPages[i]; //addedTab.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top; addedTab.Controls.Add(child); } tabMetadataTypes.Visible = true; } } }
public static void Run() { // ExStart:ReadAndWriteXMPDataToImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Specify the size of image by defining a Rectangle Rectangle rect = new Rectangle(0, 0, 100, 200); TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRgb); tiffOptions.Photometric = TiffPhotometrics.MinIsBlack; tiffOptions.BitsPerSample = new ushort[] { 8 }; // Create the brand new image just for sample purposes using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height))) { // Create an instance of XMP-Header XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString()); // Create an instance of Xmp-TrailerPi, XMPmeta class to set different attributes XmpTrailerPi xmpTrailer = new XmpTrailerPi(true); XmpMeta xmpMeta = new XmpMeta(); xmpMeta.AddAttribute("Author", "Mr Smith"); xmpMeta.AddAttribute("Description", "The fake metadata value"); // Create an instance of XmpPacketWrapper that contains all metadata XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader,xmpTrailer, xmpMeta); // Create an instacne of Photoshop package and set photoshop attributes PhotoshopPackage photoshopPackage = new PhotoshopPackage(); photoshopPackage.SetCity("London"); photoshopPackage.SetCountry("England"); photoshopPackage.SetColorMode(ColorMode.Rgb); photoshopPackage.SetCreatedDate(DateTime.UtcNow); // Add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage); // Create an instacne of DublinCore package and set dublinCore attributes DublinCorePackage dublinCorePackage = new DublinCorePackage(); dublinCorePackage.SetAuthor("Charles Bukowski"); dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); dublinCorePackage.AddValue("dc:movie", "Barfly"); // Add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage); using (var ms = new MemoryStream()) { // Update XMP metadata into image and Save image on the disk or in memory stream image.XmpData = xmpData; image.Save(ms); ms.Seek(0, System.IO.SeekOrigin.Begin); // Load the image from moemory stream or from disk to read/get the metadata using (var img = (TiffImage)Image.Load(ms)) { // Getting the XMP metadata XmpPacketWrapper imgXmpData = img.XmpData; foreach (XmpPackage package in imgXmpData.Packages) { // Use package data ... } } } } }
public static void Run() { Console.WriteLine("Running example ReadAndWriteXMPDataToImages"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Specify the size of image by defining a Rectangle Rectangle rect = new Rectangle(0, 0, 100, 200); TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRgb); tiffOptions.Photometric = TiffPhotometrics.MinIsBlack; tiffOptions.BitsPerSample = new ushort[] { 8 }; // Create the brand new image just for sample purposes using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height))) { // Create an instance of XMP-Header XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString()); // Create an instance of Xmp-TrailerPi, XMPmeta class to set different attributes XmpTrailerPi xmpTrailer = new XmpTrailerPi(true); XmpMeta xmpMeta = new XmpMeta(); xmpMeta.AddAttribute("Author", "Mr Smith"); xmpMeta.AddAttribute("Description", "The fake metadata value"); // Create an instance of XmpPacketWrapper that contains all metadata XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta); // Create an instacne of Photoshop package and set photoshop attributes PhotoshopPackage photoshopPackage = new PhotoshopPackage(); photoshopPackage.SetCity("London"); photoshopPackage.SetCountry("England"); photoshopPackage.SetColorMode(ColorMode.Rgb); photoshopPackage.SetCreatedDate(DateTime.UtcNow); // Add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage); // Create an instacne of DublinCore package and set dublinCore attributes DublinCorePackage dublinCorePackage = new DublinCorePackage(); dublinCorePackage.SetAuthor("Charles Bukowski"); dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); dublinCorePackage.AddValue("dc:movie", "Barfly"); // Add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage); using (var ms = new MemoryStream()) { // Update XMP metadata into image and Save image on the disk or in memory stream image.XmpData = xmpData; image.Save(ms); ms.Seek(0, System.IO.SeekOrigin.Begin); // Load the image from moemory stream or from disk to read/get the metadata using (var img = (TiffImage)Image.Load(ms)) { // Getting the XMP metadata XmpPacketWrapper imgXmpData = img.XmpData; foreach (XmpPackage package in imgXmpData.Packages) { // Use package data ... } } } } Console.WriteLine("Finished example ReadAndWriteXMPDataToImages"); }
/// <summary> /// Updates IPTC metadata in XMP in Jpeg file /// </summary> public static void UpdateIPTCPhotoMetadataFromXMP() { try { //ExStart:UpdateIPTCPhotoMetadataFromXMP // get xmp metadata XmpPacketWrapper xmpWrapper = MetadataUtility.ExtractXmpPackage(Common.MapSourceFilePath(filePath)); if (xmpWrapper == null) { xmpWrapper = new XmpPacketWrapper(); } // add iptc4xmpcore if not exist if (!xmpWrapper.ContainsPackage(Namespaces.Iptc4XmpCore)) { xmpWrapper.AddPackage(new IptcCorePackage()); } // get iptc4XmpCore package IptcCorePackage iptcCorePackage = (IptcCorePackage)xmpWrapper.GetPackage(Namespaces.Iptc4XmpCore); // set country code iptcCorePackage.CountryCode = "new country code"; // set sublocation iptcCorePackage.Sublocation = "new sublocation"; // update intellectual genre iptcCorePackage.IntellectualGenre = "music"; // save changes to another file MetadataUtility.UpdateMetadata(Common.MapSourceFilePath(filePath), new XmpMetadata(xmpWrapper), Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateIPTCPhotoMetadataFromXMP } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Gets IPTC metadata from XMP in Jpeg file /// </summary> public static void GetIPTCPhotoMetadataFromXMP() { try { //ExStart:GetIPTCPhotoMetadataFromXMP // get xmp metadata XmpPacketWrapper xmpWrapper = MetadataUtility.ExtractXmpPackage(Common.MapSourceFilePath(filePath)); if (xmpWrapper == null) { xmpWrapper = new XmpPacketWrapper(); } // add iptc4xmpcore if not exist if (!xmpWrapper.ContainsPackage(Namespaces.Iptc4XmpCore)) { xmpWrapper.AddPackage(new IptcCorePackage()); } // get iptc4XmpCore package IptcCorePackage iptcCorePackage = (IptcCorePackage)xmpWrapper.GetPackage(Namespaces.Iptc4XmpCore); Console.WriteLine("Country Code: {0}", iptcCorePackage.CountryCode); Console.WriteLine("Sub Location: {0}", iptcCorePackage.Sublocation); Console.WriteLine("Intellectual Genre: {0}", iptcCorePackage.IntellectualGenre); //ExEnd:GetIPTCPhotoMetadataFromXMP } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates Basic Job XMP data of Jpeg file and creates output file /// </summary> public static void UpdateBasicJobXMPProperties() { try { //ExStart:UpdateBasicJobTicketXmpPropertiesJpegImage // initialize JpegFormat JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath)); // get xmp data var xmp = jpegFormat.GetXmpData(); BasicJobTicketPackage package = null; // looking for the BasicJob schema if xmp data is presented if (xmp != null) { package = xmp.GetPackage(Namespaces.BasicJob) as BasicJobTicketPackage; } else { xmp = new XmpPacketWrapper(); } if (package == null) { // create package if not exist package = new BasicJobTicketPackage(); // and add it to xmp data xmp.AddPackage(package); } // create array of jobs Job[] jobs = new Job[1]; jobs[0] = new Job() { Id = "1", Name = "test job" }; // update schema package.SetJobs(jobs); // update xmp data jpegFormat.SetXmpData(xmp); // commit changes jpegFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateBasicJobTicketXmpPropertiesJpegImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); //ExStart:CreateXMPMetadata // Specify the size of image by defining a Rectangle Rectangle rect = new Rectangle(0, 0, 100, 200); // Create the brand new image just for sample purposes using (var image = new PsdImage(rect.Width, rect.Height)) { // Create an instance of XMP-Header XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString()); // Create an instance of Xmp-TrailerPi, XMPmeta class to set different attributes XmpTrailerPi xmpTrailer = new XmpTrailerPi(true); XmpMeta xmpMeta = new XmpMeta(); xmpMeta.AddAttribute("Author", "Mr Smith"); xmpMeta.AddAttribute("Description", "The fake metadata value"); // Create an instance of XmpPacketWrapper that contains all metadata XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta); // Create an instacne of Photoshop package and set photoshop attributes PhotoshopPackage photoshopPackage = new PhotoshopPackage(); photoshopPackage.SetCity("London"); photoshopPackage.SetCountry("England"); photoshopPackage.SetColorMode(ColorMode.Rgb); photoshopPackage.SetCreatedDate(DateTime.UtcNow); // Add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage); // Create an instacne of DublinCore package and set dublinCore attributes DublinCorePackage dublinCorePackage = new DublinCorePackage(); dublinCorePackage.SetAuthor("Mudassir Fayyaz"); dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); dublinCorePackage.AddValue("dc:movie", "Barfly"); // Add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage); using (var ms = new MemoryStream()) { // Update XMP metadata into image and Save image on the disk or in memory stream image.XmpData = xmpData; image.Save(ms); image.Save(dataDir + "ee.psd"); ms.Seek(0, System.IO.SeekOrigin.Begin); // Load the image from memory stream or from disk to read/get the metadata using (var img = (PsdImage)Image.Load(ms)) { // Getting the XMP metadata XmpPacketWrapper imgXmpData = img.XmpData; foreach (XmpPackage package in imgXmpData.Packages) { // Use package data ... } } } } //ExEnd:CreateXMPMetadata }
//ExEnd:ApplyLicense public static string CleanFile(string filePath) { try { try { //Apply license... ApplyLicense(); } catch (Exception exp) { MessageBox.Show("In Licence: " + exp.Message); } try { //Recognize format of file... FormatBase format = FormatFactory.RecognizeFormat(filePath); if (format.Type.ToString().ToLower() == "doc" || format.Type.ToString().ToLower() == "docx") { // initialize DocFormat... DocFormat docFormat = format as DocFormat; if (docFormat != null) { // get document properties... DocMetadata properties = new DocMetadata(); properties = docFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.ContentStatus = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; //Update metadata if file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "xls" || format.Type.ToString().ToLower() == "xlsx") { //Initialize XlsFormat... XlsFormat xlsFormat = format as XlsFormat; if (xlsFormat != null) { //Get document properties... XlsMetadata properties = xlsFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata in files... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "ppt" || format.Type.ToString().ToLower() == "pptx") { //Initialize PptFormat... PptFormat pptFormat = format as PptFormat; if (pptFormat != null) { //Get document properties... PptMetadata properties = pptFormat.DocumentProperties; //Remove custom properties foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "pdf") { // initialize PdfFormat... PdfFormat pdfFormat = format as PdfFormat; if (pdfFormat != null) { // get document properties... PdfMetadata properties = pdfFormat.DocumentProperties; // Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.CreatedDate = DateTime.MinValue; properties.Keywords = ""; properties.ModifiedDate = DateTime.MinValue; properties.Subject = ""; properties.TrappedFlag = false; properties.Title = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "jpeg" || format.Type.ToString().ToLower() == "jpg") { //Get EXIF data if exists ExifMetadata exifMetadata = (ExifMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.EXIF); //Get XMP data if exists XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); if (exifMetadata != null) { //Remove exif info... ExifInfo exifInfo = exifMetadata.Data; if (exifInfo.GPSData != null) { // set altitude, latitude and longitude to null values exifInfo.GPSData.Altitude = null; exifInfo.GPSData.Latitude = null; exifInfo.GPSData.LatitudeRef = null; exifInfo.GPSData.Longitude = null; exifInfo.GPSData.LongitudeRef = null; } exifInfo.BodySerialNumber = ""; exifInfo.CameraOwnerName = ""; exifInfo.CFAPattern = new byte[] { 0 }; } else { exifMetadata = new ExifMetadata(); } try { //Remove XMP data... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; } } } catch { } //Update Exif info... try { MetadataUtility.UpdateMetadata(filePath, exifMetadata); } catch { } //Update XMP data... try { MetadataUtility.UpdateMetadata(filePath, xmpMetadata); } catch { } //Remove custom metadata if any... MetadataUtility.CleanMetadata(filePath); return("1"); } else if (format.Type.ToString().ToLower() == "png") { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { //Remove XMP metadata... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update XMP metadata in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } return("1"); } else if (format.Type.ToString().ToLower() == "gif") { //Initialie GifFormat... GifFormat gifFormat = new GifFormat(filePath); //Check if Xmp supported... if (gifFormat.IsSupportedXmp) { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update Xmp data in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } } return("1"); } else { return("Format not supported."); } } catch (Exception exp) { MessageBox.Show("Exception: " + exp.Message); return(exp.Message); } } catch (Exception exp) { return(exp.Message); } }