Example #1
0
            /// <summary>
            /// Gets custom properties of Pdf file
            /// </summary>
            public static void GetCustomProperties()
            {
                try
                {
                    //ExStart:GetCustomDocumentPropertiesPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata pdfMetadata = pdfFormat.DocumentProperties;

                    Console.WriteLine("\nCustom Properties");
                    foreach (KeyValuePair <string, PropertyValue> keyValuePair in pdfMetadata)
                    {
                        // check if property is not built-in
                        if (!pdfMetadata.IsBuiltIn(keyValuePair.Key))
                        {
                            // get property value
                            PropertyValue propertyValue = pdfMetadata[keyValuePair.Key];
                            Console.WriteLine("Key: {0}, Type:{1}, Value: {2}", keyValuePair.Key, propertyValue.Type, propertyValue);
                        }
                    }
                    //ExEnd:GetCustomDocumentPropertiesPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Example #2
0
            /// <summary>
            /// Removes custom property of Pdf file and creates output file
            /// </summary>
            public static void RemoveCustomProperties()
            {
                try
                {
                    //ExStart:RemoveCustomDocumentPropertiesPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata metadata = pdfFormat.DocumentProperties;

                    string propertyName = "New Custom Property";

                    // check if property is not built-in
                    if (!metadata.IsBuiltIn(propertyName))
                    {
                        // remove property
                        metadata.Remove(propertyName);
                    }
                    else
                    {
                        Console.WriteLine("Can not remove built-in property.");
                    }

                    // save file in destination folder
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveCustomDocumentPropertiesPdfFormat
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Example #3
0
            /// <summary>
            /// Updates document properties of Pdf file and creates output file
            /// </summary>
            public static void UpdateDocumentProperties()
            {
                try
                {
                    //ExStart:UpdateBuiltinDocumentPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata pdfMetadata = pdfFormat.DocumentProperties;

                    //update document property...
                    pdfMetadata.Author      = "New author";
                    pdfMetadata.Subject     = "New subject";
                    pdfMetadata.CreatedDate = DateTime.Now;

                    //save output file...
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));

                    //ExEnd:UpdateBuiltinDocumentPropertyPdfFormat
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Example #4
0
            /// <summary>
            /// Adds custom property in Pdf file and creates output file
            /// </summary>
            public static void AddCustomProperty()
            {
                try
                {
                    //ExStart:AddCustomDocumentPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata metadata = pdfFormat.DocumentProperties;

                    string propertyName  = "New Custom Property";
                    string propertyValue = "123";


                    // check if property already exists
                    if (!metadata.ContainsKey(propertyName))
                    {
                        // add property
                        metadata.Add(propertyName, propertyValue);
                    }

                    // save file in destination folder
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:AddCustomDocumentPropertyPdfFormat
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Example #5
0
            //ExEnd:SourcePdfFilePath
            #region working with builtin document properties
            /// <summary>
            /// Gets builtin document properties of Pdf file
            /// </summary>
            public static void GetDocumentProperties()
            {
                try
                {
                    //ExStart:GetBuiltinDocumentPropertyPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata pdfMetadata = pdfFormat.DocumentProperties;

                    // built-in properties
                    Console.WriteLine("Built-in Properties");
                    foreach (KeyValuePair <string, PropertyValue> property in pdfMetadata)
                    {
                        // check if built-in property
                        if (pdfMetadata.IsBuiltIn(property.Key))
                        {
                            Console.WriteLine("{0} : {1}", property.Key, property.Value);
                        }
                    }
                    //ExEnd:GetBuiltinDocumentPropertyPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Example #6
0
        public IFormat HandleRequest(int format)
        {
            IFormat extension = null;

            if (format == 7)
            {
                extension = new PdfFormat();
            }
            else if (Successor != null)
            {
                Successor.HandleRequest(format);
            }
            return(extension);
        }
Example #7
0
            /// <summary>
            /// Removes document properties of Pdf file and creates output file
            /// </summary>
            public static void RemoveDocumentProperties()
            {
                try
                {
                    //ExStart:RemoveBuiltinDocumentPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    pdfFormat.CleanMetadata();

                    //save output file...
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveBuiltinDocumentPropertyPdfFormat

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Example #8
0
        public static IFormat ChooseFormat(int index)
        {
            IFormat format = null;

            switch (index)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5: format = new BaseFormats(); break;

            case 6: format = new XpsFormat(); break;

            case 7: format = new PdfFormat(); break;

            case 8: format = new PsdFormat(); break;

            default: break;
            }

            return(format);
        }
            /// <summary>
            /// Gets custom properties of Pdf file
            /// </summary>
            public static void GetCustomProperties()
            {
                try
                {
                    //ExStart:GetCustomDocumentPropertiesPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata pdfMetadata = pdfFormat.DocumentProperties;

                    Console.WriteLine("\nCustom Properties");
                    foreach (KeyValuePair<string, PropertyValue> keyValuePair in pdfMetadata)
                    {
                        // check if property is not built-in
                        if (!pdfMetadata.IsBuiltIn(keyValuePair.Key))
                        {
                            // get property value
                            PropertyValue propertyValue = pdfMetadata[keyValuePair.Key];
                            Console.WriteLine("Key: {0}, Type:{1}, Value: {2}", keyValuePair.Key, propertyValue.Type, propertyValue);
                        }
                    }
                    //ExEnd:GetCustomDocumentPropertiesPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Adds custom property in Pdf file and creates output file
            /// </summary> 
            public static void AddCustomProperty()
            {
                try
                {
                    //ExStart:AddCustomDocumentPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata metadata = pdfFormat.DocumentProperties;

                    string propertyName = "New Custom Property";
                    string propertyValue = "123";


                    // check if property already exists
                    if (!metadata.ContainsKey(propertyName))
                    {
                        // add property
                        metadata.Add(propertyName, propertyValue);
                    }

                    // save file in destination folder
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:AddCustomDocumentPropertyPdfFormat
                    Console.WriteLine("File saved in destination folder.");


                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Removes document properties of Pdf file and creates output file
            /// </summary> 
            public static void RemoveDocumentProperties()
            {
                try
                {
                    //ExStart:RemoveBuiltinDocumentPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    pdfFormat.CleanMetadata();

                    //save output file...
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveBuiltinDocumentPropertyPdfFormat

                    Console.WriteLine("File saved in destination folder.");


                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates document properties of Pdf file and creates output file
            /// </summary> 
            public static void UpdateDocumentProperties()
            {
                try
                {

                    //ExStart:UpdateBuiltinDocumentPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata pdfMetadata = pdfFormat.DocumentProperties;

                    //update document property...
                    pdfMetadata.Author = "New author";
                    pdfMetadata.Subject = "New subject";
                    pdfMetadata.CreatedDate = DateTime.Now;

                    //save output file...
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));

                    //ExEnd:UpdateBuiltinDocumentPropertyPdfFormat
                    Console.WriteLine("File saved in destination folder.");

                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }

            }
            public static void RemoveHiddenData()
            {
                try
                {
                    //ExStart:RemoveHiddenDataPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // inspect document
                    PdfInspectionResult inspectionResult = pdfFormat.InspectDocument();

                    // get annotations
                    PdfAnnotation[] annotation = inspectionResult.Annotations;

                    // if annotations are presented
                    if (annotation.Length > 0)
                    {
                        // remove all annotation
                        pdfFormat.RemoveHiddenData(new PdfInspectionOptions(PdfInspectorOptionsEnum.Annotations));

                        //save output file...
                        pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    }
                    //ExEnd:RemoveHiddenDataPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Gets XMP Data of Pdf file  
            /// </summary> 
            public static void GetXMPProperties()
            {
                try
                {
                    //ExStart:GetXMPPropertiesPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // get pdf schema
                    PdfPackage pdfPackage = pdfFormat.XmpValues.Schemes.Pdf;

                    Console.WriteLine("Keywords: {0}", pdfPackage.Keywords);
                    Console.WriteLine("PdfVersion: {0}", pdfPackage.PdfVersion);
                    Console.WriteLine("Producer: {0}", pdfPackage.Producer);
                    //ExEnd:GetXMPPropertiesPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
        public JsonResult <List <PropertyItem> > Get(string file)
        {
            try
            {
                FileStream        original          = File.Open(Utils._storagePath + "\\" + file, FileMode.OpenOrCreate);
                FileFormatChecker fileFormatChecker = new FileFormatChecker(original);

                DocumentType        documentType = fileFormatChecker.GetDocumentType();
                List <PropertyItem> values       = new List <PropertyItem>();

                if (fileFormatChecker.VerifyFormat(documentType))
                {
                    switch (documentType)
                    {
                    case DocumentType.Doc:

                        DocFormat docFormat = new DocFormat(original);
                        values = AppendMetadata(docFormat.GetMetadata(), values);

                        break;

                    case DocumentType.Xls:

                        XlsFormat xlsFormat = new XlsFormat(original);
                        values = AppendMetadata(xlsFormat.GetMetadata(), values);

                        break;

                    case DocumentType.Pdf:

                        PdfFormat pdfFormat = new PdfFormat(original);
                        values = AppendMetadata(pdfFormat.GetMetadata(), values);
                        values = AppendXMPData(pdfFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Png:

                        PngFormat pngFormat = new PngFormat(original);
                        values = AppendMetadata(pngFormat.GetMetadata(), values);
                        values = AppendXMPData(pngFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Jpeg:

                        JpegFormat jpegFormat = new JpegFormat(original);
                        values = AppendMetadata(jpegFormat.GetMetadata(), values);
                        values = AppendXMPData(jpegFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Gif:

                        GifFormat gifFormat = new GifFormat(original);
                        values = AppendMetadata(gifFormat.GetMetadata(), values);
                        values = AppendXMPData(gifFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Bmp:

                        BmpFormat bmpFormat = new BmpFormat(original);
                        values = AppendMetadata(bmpFormat.GetMetadata(), values);

                        break;

                    case DocumentType.Msg:

                        OutlookMessage outlookMessage = new OutlookMessage(original);
                        values = AppendMetadata(outlookMessage.GetMsgInfo(), values);
                        break;

                    case DocumentType.Eml:

                        EmlFormat emlFormat = new EmlFormat(original);
                        values = AppendMetadata(emlFormat.GetEmlInfo(), values);
                        break;

                    case DocumentType.Dwg:

                        DwgFormat dwgFormat = new DwgFormat(original);
                        values = AppendMetadata(dwgFormat.GetMetadata(), values);
                        break;

                    case DocumentType.Dxf:

                        DxfFormat dxfFormat = new DxfFormat(original);
                        values = AppendMetadata(dxfFormat.GetMetadata(), values);
                        break;

                    default:

                        DocFormat defaultDocFormat = new DocFormat(original);
                        values = AppendMetadata(defaultDocFormat.GetMetadata(), values);

                        break;
                    }

                    return(Json(values));
                }
                else
                {
                    throw new Exception("File format not supported.");
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
            /// <summary>
            /// Removes custom property of Pdf file and creates output file
            /// </summary> 
            public static void RemoveCustomProperties()
            {
                try
                {
                    //ExStart:RemoveCustomDocumentPropertiesPdfFormat
                    // initialize PdfFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata metadata = pdfFormat.DocumentProperties;

                    string propertyName = "New Custom Property";

                    // check if property is not built-in
                    if (!metadata.IsBuiltIn(propertyName))
                    {
                        // remove property
                        metadata.Remove(propertyName);
                    }
                    else
                    {
                        Console.WriteLine("Can not remove built-in property.");
                    }

                    // save file in destination folder
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveCustomDocumentPropertiesPdfFormat
                    Console.WriteLine("File saved in destination folder.");

                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Clears custom properties of Pdf file and creates output file
            /// </summary> 
            public static void ClearCustomProperties()
            {
                try
                {
                    //ExStart:ClearCustomPropertyPdfFormat
                    // initialize PdfFormat
                    PdfFormat PdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // use one of the following methods
                    // method:1 - clear custom properties 
                    PdfFormat.ClearCustomProperties();

                    // method:2 - clear custom properties
                    PdfFormat.DocumentProperties.ClearCustomData();

                    // save file in destination folder
                    PdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:ClearCustomPropertyPdfFormat
                    Console.WriteLine("File saved in destination folder.");

                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
        /// <summary>
        /// Detects document protection
        /// </summary> 
        public static void DetectProtection(string filePath)
        {
            try
            {
                //ExStart:DetectProtection
                FormatBase format = FormatFactory.RecognizeFormat(Common.MapSourceFilePath(filePath));

                if (format.Type.ToString().ToLower() == "doc")
                {
                    // initialize DocFormat
                    DocFormat docFormat = new DocFormat(Common.MapSourceFilePath(filePath));

                    // determines whether document is protected by password
                    Console.WriteLine(docFormat.IsProtected ? "Document is protected" : "Document is protected");
                }
                else if (format.Type.ToString().ToLower() == "pdf")
                {
                    // initialize DocFormat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // determines whether document is protected by password
                    Console.WriteLine(pdfFormat.IsProtected ? "Document is protected" : "Document is protected");
                }
                else if (format.Type.ToString().ToLower() == "xls")
                {
                    // initialize DocFormat
                    XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath));

                    // determines whether document is protected by password
                    Console.WriteLine(xlsFormat.IsProtected ? "Document is protected" : "Document is protected");
                }
                else if (format.Type.ToString().ToLower() == "ppt")
                {
                    // initialize DocFormat
                    PptFormat pptFormat = new PptFormat(Common.MapSourceFilePath(filePath));

                    // determines whether document is protected by password
                    Console.WriteLine(pptFormat.IsProtected ? "Document is protected" : "Document is protected");
                }
                else
                {
                    Console.WriteLine("Invalid Format.");
                }
                //ExEnd:DetectProtection
            }
            catch (Exception exp)
            {
                Console.WriteLine("Exception occurred: " + exp.Message);
            }

        }
            /// <summary>
            /// Updates XMP Data of Pdf file  
            /// </summary> 
            public static void UpdateXMPProperties()
            {
                try
                {
                    //ExStart:UpdateXMPPropertiesPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // get pdf schema
                    PdfPackage pdfPackage = pdfFormat.XmpValues.Schemes.Pdf;

                    // update keywords
                    pdfPackage.Keywords = "literature, programming";

                    // update pdf version
                    pdfPackage.PdfVersion = "1.0";

                    // pdf:Producer could not be updated
                    //pdfPackage.Producer="";

                    //save output file...
                    pdfFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateXMPPropertiesPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            //ExEnd:SourcePdfFilePath
            #region working with builtin document properties
            /// <summary>
            /// Gets builtin document properties of Pdf file  
            /// </summary> 
            public static void GetDocumentProperties()
            {
                try
                {
                    //ExStart:GetBuiltinDocumentPropertyPdfFormat
                    // initialize Pdfformat
                    PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath));

                    // initialize PdfMetadata
                    PdfMetadata pdfMetadata = pdfFormat.DocumentProperties;

                    // built-in properties
                    Console.WriteLine("Built-in Properties");
                    foreach (KeyValuePair<string, PropertyValue> property in pdfMetadata)
                    {
                        // check if built-in property
                        if (pdfMetadata.IsBuiltIn(property.Key))
                        {
                            Console.WriteLine("{0} : {1}", property.Key, property.Value);
                        }
                    }
                    //ExEnd:GetBuiltinDocumentPropertyPdfFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
        //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);
            }
        }
        public HttpResponseMessage Get(string file)
        {
            try
            {
                File.Copy(Utils._storagePath + "\\" + file, Utils._storagePath + "\\Cleaned_" + file, true);
                FileStream        original          = File.Open(Utils._storagePath + "\\Cleaned_" + file, FileMode.Open, FileAccess.ReadWrite);
                FileFormatChecker fileFormatChecker = new FileFormatChecker(original);
                DocumentType      documentType      = fileFormatChecker.GetDocumentType();


                if (fileFormatChecker.VerifyFormat(documentType))
                {
                    switch (documentType)
                    {
                    case DocumentType.Doc:

                        DocFormat docFormat = new DocFormat(original);
                        docFormat.CleanMetadata();
                        docFormat.ClearBuiltInProperties();
                        docFormat.ClearComments();
                        docFormat.ClearCustomProperties();
                        docFormat.RemoveHiddenData(new DocInspectionOptions(DocInspectorOptionsEnum.All));

                        docFormat.Save(Utils._storagePath + "\\Cleaned_" + file);
                        break;

                    case DocumentType.Xls:

                        XlsFormat xlsFormat = new XlsFormat(original);
                        xlsFormat.CleanMetadata();
                        xlsFormat.ClearBuiltInProperties();
                        xlsFormat.ClearContentTypeProperties();
                        xlsFormat.ClearCustomProperties();
                        xlsFormat.RemoveHiddenData(new XlsInspectionOptions(XlsInspectorOptionsEnum.All));

                        xlsFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Pdf:

                        PdfFormat pdfFormat = new PdfFormat(original);
                        pdfFormat.CleanMetadata();
                        pdfFormat.ClearBuiltInProperties();
                        pdfFormat.ClearCustomProperties();
                        pdfFormat.RemoveHiddenData(new PdfInspectionOptions(PdfInspectorOptionsEnum.All));
                        pdfFormat.RemoveXmpData();

                        pdfFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Png:

                        PngFormat pngFormat = new PngFormat(original);
                        pngFormat.CleanMetadata();
                        pngFormat.RemoveXmpData();

                        pngFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Jpeg:

                        JpegFormat jpegFormat = new JpegFormat(original);
                        jpegFormat.CleanMetadata();
                        jpegFormat.RemoveExifInfo();
                        jpegFormat.RemoveGpsLocation();
                        jpegFormat.RemoveIptc();
                        jpegFormat.RemovePhotoshopData();
                        jpegFormat.RemoveXmpData();

                        jpegFormat.Save(original);

                        break;

                    case DocumentType.Bmp:

                        BmpFormat bmpFormat = new BmpFormat(original);
                        bmpFormat.CleanMetadata();

                        bmpFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Gif:

                        GifFormat gifFormat = new GifFormat(original);
                        gifFormat.CleanMetadata();
                        gifFormat.RemoveXmpData();

                        gifFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Msg:

                        OutlookMessage outlookMessage = new OutlookMessage(original);
                        outlookMessage.CleanMetadata();
                        outlookMessage.RemoveAttachments();

                        outlookMessage.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Eml:

                        EmlFormat emlFormat = new EmlFormat(original);
                        emlFormat.CleanMetadata();
                        emlFormat.RemoveAttachments();

                        emlFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Dwg:

                        DwgFormat dwgFormat = new DwgFormat(original);
                        dwgFormat.CleanMetadata();

                        dwgFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Dxf:

                        DxfFormat dxfFormat = new DxfFormat(original);
                        dxfFormat.CleanMetadata();

                        dxfFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    default:

                        DocFormat defaultDocFormat = new DocFormat(original);
                        defaultDocFormat.CleanMetadata();
                        defaultDocFormat.ClearBuiltInProperties();
                        defaultDocFormat.ClearComments();
                        defaultDocFormat.ClearCustomProperties();
                        defaultDocFormat.RemoveHiddenData(new DocInspectionOptions(DocInspectorOptionsEnum.All));

                        defaultDocFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;
                    }
                }
                else
                {
                    throw new Exception("File format not supported.");
                }

                using (var ms = new MemoryStream())
                {
                    original = File.OpenRead(Utils._storagePath + "\\Cleaned_" + file);
                    original.CopyTo(ms);
                    var result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ByteArrayContent(ms.ToArray())
                    };
                    result.Content.Headers.ContentDisposition =
                        new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                    {
                        FileName = "Cleaned_" + file
                    };
                    result.Content.Headers.ContentType =
                        new MediaTypeHeaderValue("application/octet-stream");

                    original.Close();
                    File.Delete(Utils._storagePath + "\\Cleaned_" + file);
                    return(result);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }