Here is the code:
using GroupDocs.Metadata;
using GroupDocs.Metadata.Formats;
using GroupDocs.Metadata.Formats.Document;
using GroupDocs.Metadata.Formats.Image;
using GroupDocs.Metadata.Xmp;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
public static string inputFilePath = @“S:\DublinCore-XmpBasic -Code doc.pdf”;
public static string outputFilePath = @“S:\DublinCore-XmpBasic -Code doc-123.pdf”;
static void Main(string[] args)
{
License lic = new License();
lic.SetLicense(@"S:\GroupDocs.total.lic");
FormatBase format = null;
string extension = Path.GetExtension(inputFilePath).ToLower();
switch (extension)
{
case ".gif":
{
format = new GifFormat(inputFilePath);
if (format == null || !((GifFormat)format).IsSupportedXmp)
{
return;
}
XmpEditableCollection _xmpEditableCollection = ((GifFormat)format).XmpValues;
XmpSchemes _schemes = _xmpEditableCollection.Schemes;
RemoveMetaData(_schemes);
break;
}
case ".png":
{
format = new PngFormat(inputFilePath);
if (format == null)
{
return;
}
XmpEditableCollection _xmpEditableCollection = ((PngFormat)format).XmpValues;
XmpSchemes _schemes = _xmpEditableCollection.Schemes;
RemoveMetaData(_schemes);
break;
}
case ".pdf":
{
format = new PdfFormat(inputFilePath);
if (format == null)
{
return;
}
XmpEditableCollection _xmpEditableCollection = ((PdfFormat)format).XmpValues;
XmpSchemes _schemes = _xmpEditableCollection.Schemes;
RemoveMetaData(_schemes);
// Remove document properties:
// Author, Category, Comments, CreatedDate, Company, HyperlinkBase, Keywords, Manager, ModifiedDate, Subject, Title
PdfMetadata metaData = ((PdfFormat)format).DocumentProperties;
metaData.Title = string.Empty;
metaData.Author = string.Empty;
break;
}
case ".xlsx":
{
format = new XlsFormat(inputFilePath);
if (format == null)
{
return;
}
// Remove document properties:
// Author, Category, Comments, CreatedDate, Company, HyperlinkBase, Keywords, Manager, ModifiedDate, Subject, Title
XlsMetadata metaData = ((XlsFormat)format).DocumentProperties;
metaData.Title = string.Empty;
metaData.Author = string.Empty;
break;
}
default:
return;
}
format.Save(outputFilePath);
}
private static void RemoveMetaData(XmpSchemes schemes)
{
// Remove XMP DublinCorePackage metadata:
// Contributors, Creators, Source, Subject
schemes.DublinCore.Source = string.Empty;
schemes.DublinCore.Subject = string.Empty;
// Remove XMP PdfPackage metadata:
// Keywords, Producer
schemes.Pdf.Keywords = string.Empty;
schemes.Pdf.Producer = string.Empty;
// Remove XMP PhotoshopPackage metadata:
// AuthorsPosition, CaptionWriter, City, Country, Credit, DateCreated, Headline, History, Instructions, Source, State
schemes.Photoshop.City = string.Empty;
schemes.Photoshop.Country = string.Empty;
// Remove XMP XmpBasicPackage metadata:
// BaseUrl, CreateDate, CreatorTool, Label, MetadataDate, ModifyDate, Nickname
schemes.XmpBasic.BaseUrl = string.Empty;
schemes.XmpBasic.Nickname = string.Empty;
}
}
}