/// <summary>
            /// Updates XMP data of Png file and creates output file
            /// </summary>
            public static void UpdateXMPData()
            {
                try
                {
                    //ExStart:UpdateXMPPropertiesPngImage
                    // 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));
                    //ExEnd:UpdateXMPPropertiesPngImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Removes XMP data of Png file and creates output file
            /// </summary>
            public static void RemoveXMPData()
            {
                try
                {
                    //ExStart:RemoveXMPPropertiesPngImage
                    // initialize PngFormat
                    PngFormat pngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    // remove XMP package
                    pngFormat.RemoveXmpData();

                    // commit changes
                    pngFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveXMPPropertiesPngImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Removes XMP data of Png file and creates output file
            /// </summary> 
            public static void RemoveXMPData()
            {
                try
                {
                    //ExStart:RemoveXMPPropertiesPngImage 
                    // initialize PngFormat
                    PngFormat pngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    // remove XMP package
                    pngFormat.RemoveXmpData();

                    // commit changes
                    pngFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveXMPPropertiesPngImage 
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates thumbnails in XMP data of Png file and creates output file
            /// </summary> 
            public static void UpdateThumbnailInXMPData()
            {
                try
                {
                    //ExStart:UpdateThumbnailXmpPropertiesPngImage

                    string path = Common.MapSourceFilePath(filePath);
                    // initialize PngFormat
                    PngFormat pngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    // get image base64 string
                    string base64String;
                    using (Image image = Image.FromFile(path))
                    {
                        using (MemoryStream m = new MemoryStream())
                        {
                            image.Save(m, image.RawFormat);
                            byte[] imageBytes = m.ToArray();

                            // Convert byte[] to Base64 String
                            base64String = Convert.ToBase64String(imageBytes);
                        }
                    }

                    // create image thumbnail
                    Thumbnail thumbnail = new Thumbnail { ImageBase64 = base64String };

                    // initialize array and add thumbnail
                    Thumbnail[] thumbnails = new Thumbnail[1];
                    thumbnails[0] = thumbnail;

                    // update thumbnails property in XMP Basic schema
                    pngFormat.XmpValues.Schemes.XmpBasic.Thumbnails = thumbnails;

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

                    //ExEnd:UpdateThumbnailXmpPropertiesPngImage

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates Basic Job XMP data of Png file and creates output file
            /// </summary> 
            public static void UpdateBasicJobXMPProperties()
            {
                try
                {
                    //ExStart:UpdateBasicJobTicketXmpPropertiesPngImage
                    // initialize PngFormat
                    PngFormat pngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    // get xmp data
                    var xmp = pngFormat.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
                    pngFormat.SetXmpData(xmp);

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

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates CameraRaw XMP data of Png file and creates output file
            /// </summary> 
            public static void UpdateCameraRawXMPProperties()
            {
                try
                {
                    //ExStart:UpdateCameraRawXmpPropertiesPngImage
                    // initialize PngFormat
                    PngFormat PngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    // get access to CameraRaw schema
                    var package = PngFormat.XmpValues.Schemes.CameraRaw;

                    // update properties
                    package.AutoBrightness = true;
                    package.AutoContrast = true;
                    package.CropUnits = CropUnits.Pixels;

                    // update white balance
                    package.SetWhiteBalance(WhiteBalance.Auto);

                    // commit changes
                    PngFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateCameraRawXmpPropertiesPngImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates PagedText XMP data of Png file and creates output file
            /// </summary> 
            public static void UpdatePagedTextXMPProperties()
            {
                try
                {
                    //ExStart:UpdatePagedTextXmpPropertiesPngImage
                    // initialize PngFormat
                    PngFormat PngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    // get access to PagedText schema
                    var package = PngFormat.XmpValues.Schemes.PagedText;

                    // update MaxPageSize
                    package.MaxPageSize = new Dimensions(600, 800);

                    // update number of pages
                    package.NumberOfPages = 10;

                    // update plate names
                    package.PlateNames = new string[] { "1", "2", "3" };

                    // commit changes
                    PngFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdatePagedTextXmpPropertiesPngImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates XMP values of Png file and creates output file
            /// </summary> 
            public static void UpdateXMPValues()
            {
                try
                {
                    //ExStart:UpdateXmpValuesPngImage
                    // initialize PngFormat
                    PngFormat PngFormat = new PngFormat(Common.MapSourceFilePath(filePath));

                    const string dcFormat = "test format";
                    string[] dcContributors = { "test contributor" };
                    const string dcCoverage = "test coverage";
                    const string phCity = "NY";
                    const string phCountry = "USA";
                    const string xmpCreator = "GroupDocs.Metadata";

                    PngFormat.XmpValues.Schemes.DublinCore.Format = dcFormat;
                    PngFormat.XmpValues.Schemes.DublinCore.Contributors = dcContributors;
                    PngFormat.XmpValues.Schemes.DublinCore.Coverage = dcCoverage;
                    PngFormat.XmpValues.Schemes.Photoshop.City = phCity;
                    PngFormat.XmpValues.Schemes.Photoshop.Country = phCountry;
                    PngFormat.XmpValues.Schemes.XmpBasic.CreatorTool = xmpCreator;

                    // commit changes
                    PngFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateXmpValuesPngImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates XMP data of Png file and creates output file
            /// </summary> 
            public static void UpdateXMPData()
            {
                try
                {
                    //ExStart:UpdateXMPPropertiesPngImage 
                    // 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));
                    //ExEnd:UpdateXMPPropertiesPngImage 
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(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;
            }
        }