/// <summary>
            /// configure redactions in XML and apply them to any document as a single redaction profile.
            /// </summary>
            public static void Redact_All()
            {
                //ExStart:ConfigurableRedaction_19.3

                //Initialize RedactionPolicy
                RedactionPolicy policy = RedactionPolicy.Load(Common.MapSourceFilePath("Documents/Bulk/RedactionPolicy.xml"));

                foreach (var fileEntry in Directory.GetFiles(Common.MapSourceFilePath(Inbound_Path)))
                {
                    using (Document doc = Redactor.Load(fileEntry))
                    {
                        //Apply redaction
                        RedactionSummary result = doc.RedactWith(policy.Redactions);

                        // Set output directory path
                        String resultFolder = result.Status != RedactionStatus.Failed ? Common.MapSourceFilePath(Outbound_Done_Path) : Common.MapSourceFilePath(Outbound_Failed_Path);

                        // Save the ouput files after applying redactions
                        using (Stream fileStream = File.Create(Path.Combine(resultFolder, Path.GetFileName(fileEntry))))
                        {
                            doc.Save(fileStream, new SaveOptions()
                            {
                                RasterizeToPDF = false, RedactedFileSuffix = DateTime.Now.ToString()
                            });
                            fileStream.Close();
                        }
                    }
                }
                //ExEnd:ConfigurableRedaction_19.3
            }
 /// <summary>
 /// Loads document
 /// </summary>
 public static void LoadDocument()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         // Here we can use document instance to perform redactions
     }
 }
 /// <summary>
 /// Performs a case sensitive exact phrase redaction
 /// </summary>
 public static void CaseSensitiveExactPhraseRedaction()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new ExactPhraseRedaction("John Doe", true /*isCaseSensitive*/, new ReplacementOptions("[personal]")));
         doc.Save();
     }
 }
 /// <summary>
 /// Removes sensitive information from specific annotations
 /// </summary>
 public static void RemoveSensitiveInformationFromAnnotation()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new AnnotationRedaction("(?im:john)", "[redacted]"));
         doc.Save();
     }
 }
 /// <summary>
 /// Colors redacted text
 /// </summary>
 public static void ColorRedactedText()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Black)));
         doc.Save();
     }
 }
 /// <summary>
 /// This method rejects or accepts specific changes during redaction process or keeps a full log of changes in the document
 /// </summary>
 public static void UseRedactionCallback()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         // Assign an instance before using Redactor
         Redactor.RedactionCallback = new RedactionDump();
         doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
         doc.Save();
     }
 }
 /// <summary>
 /// Loads document using stream
 /// </summary>
 public static void LoadDocumentUsingStream()
 {
     using (Stream stream = File.Open(Common.MapSourceFilePath(FilePath), FileMode.Open, FileAccess.ReadWrite))
     {
         using (Document doc = Redactor.Load(stream))
         {
             // Here we can use document instance to make redactions
         }
     }
 }
            /// <summary>
            /// Opens and performs redaction in password proteced document
            /// </summary>
            public static void PasswordProtectedDocument()
            {
                LoadOptions loadOptions = new LoadOptions("mypassword");

                using (Document doc = Redactor.Load(Common.MapSourceFilePath(ProtectedFilePath), loadOptions))
                {
                    // Here we can use document instance to perform redactions
                    doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
                    doc.Save();
                }
            }
 /// <summary>
 /// Cleans document metadata
 /// </summary>
 public static void CleanDocumentMetadata()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new EraseMetadataRedaction(MetadataFilter.All));
         // Save the document to "*_Redacted.*" file in original format
         doc.Save(new SaveOptions()
         {
             AddSuffix = true, RasterizeToPDF = false
         });
     }
 }
 /// <summary>
 /// Performs a metadata search redaction
 /// </summary>
 public static void MetadataSearchRedaction()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new MetadataSearchRedaction("Company Ltd.", "--company--"));
         // Save the document to "*_Redacted.*" file in original format
         doc.Save(new SaveOptions()
         {
             AddSuffix = true, RasterizeToPDF = false
         });
     }
 }
 /// <summary>
 /// Performs Annotation Redaction
 /// </summary>
 public static void AnnotationRedaction()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new DeleteAnnotationRedaction("(?im:(use|show|describe))"));
         // Save the document to "*_Redacted.*" file in original format
         doc.Save(new SaveOptions()
         {
             AddSuffix = true, RasterizeToPDF = false
         });
     }
 }
 /// <summary>
 /// Performs a regular expression redaction
 /// </summary>
 public static void RegularExpressionRedaction()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         doc.RedactWith(new RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}", new ReplacementOptions(System.Drawing.Color.Blue)));
         // Save the document to "*_Redacted.*" file in original format
         doc.Save(new SaveOptions()
         {
             AddSuffix = true, RasterizeToPDF = false
         });
     }
 }
        /// <summary>
        /// This method is used when for some reason files have non-standard extensions or if its format is supported, but not pre-configured.
        /// For instance, all kinds of plain text files (logs, dumps etc) could be opened with text processors like MS Word/Open Office.
        /// </summary>
        public static void WorkWithFileExtensions()
        {
            RedactorConfiguration       config       = RedactorConfiguration.GetInstance();
            DocumentFormatConfiguration docxSettings = config.FindFormat(".docx");

            docxSettings.ExtensionFilter = docxSettings.ExtensionFilter + ",.txt";
            using (Document doc = Redactor.Load(Common.MapSourceFilePath(TextFilePath)))
            {
                // Here we can use document instance to perform redactions
                doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
                doc.Save();
            }
        }
        /// <summary>
        /// This method supports a new document format(txt), it implements a handler for it by inheriting from DocumentFormatInstance class
        /// </summary>
        public static void CreateCustomFileFormat()
        {
            var config = new DocumentFormatConfiguration()
            {
                ExtensionFilter = ".txt",
                DocumentType    = typeof(PlainTextDocument)
            };

            using (Document doc = Redactor.Load(Common.MapSourceFilePath(TextFilePath), new LoadOptions(config)))
            {
                // Here we can use document instance to perform redactions
                doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]")));
                // Save the document to "*_AnyText.*" (e.g. timestamp instead of "AnyText") in its file name without rasterization
                doc.Save(new SaveOptions(false, "AnyText"));
            }
        }
 /// <summary>
 /// Opens and performs redaction in password proteced document
 /// </summary>
 public static void SpecifyPDFComplianceAndPages()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(Conversion_Control_FilePath)))
     {
         RedactionSummary result = doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Red)));
         if (result.Status != RedactionStatus.Failed)
         {
             var options = new SaveOptions();
             options.Rasterization.Enabled    = true;                        // the same as options.RasterizeToPDF = true;
             options.Rasterization.PageIndex  = 5;                           // start from 5th page
             options.Rasterization.PageCount  = 1;                           // save only one page
             options.Rasterization.Compliance = PdfComplianceLevel.PdfA1a;   // by default PdfComplianceLevel.Auto or PDF/A-1b
             options.AddSuffix = true;
             doc.Save(options);
         }
     }
 }
        /// <summary>
        /// Saves document using diffrent appraches
        /// </summary>
        public static void SaveDocument()
        {
            using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
            {
                // Document redaction goes here
                // ...

                // Save the document with default options (convert pages into images, save as PDF)
                doc.Save();

                // Save the document in original format overwriting original file
                doc.Save(new SaveOptions()
                {
                    AddSuffix = false, RasterizeToPDF = false
                });

                // Save the document to "*_Redacted.*" file in original format
                doc.Save(new SaveOptions()
                {
                    AddSuffix = true, RasterizeToPDF = false
                });

                // Save the document to "*_AnyText.*" (e.g. timestamp instead of "AnyText") in its file name without rasterization
                doc.Save(new SaveOptions(false, "AnyText"));

                // Save the document to the specified stream in original format
                using (Stream memStream = new MemoryStream())
                {
                    doc.Save(memStream, new SaveOptions()
                    {
                        RasterizeToPDF = false
                    });
                    memStream.Close();
                }

                // Save the document to a custom location and convert its pages to images
                using (Stream fileStream = File.Open(Common.MapSourceFilePath(FilePath), FileMode.Open, FileAccess.ReadWrite))
                {
                    doc.Save(fileStream, new SaveOptions()
                    {
                        RasterizeToPDF = true
                    });
                    fileStream.Close();
                }
            }
        }
 /// <summary>
 /// Performs cell column redaction in excel file format
 /// </summary>
 public static void TabularDocumentRedaction()
 {
     using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
     {
         var filter = new CellFilter()
         {
             ColumnIndex   = 1, // zero-based 2nd column
             WorkSheetName = "Customers"
         };
         var expression          = new Regex("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
         RedactionSummary result = doc.RedactWith(new CellColumnRedaction(filter, expression, new ReplacementOptions("[customer email]")));
         if (result.Success)
         {
             doc.Save(new SaveOptions()
             {
                 AddSuffix = true
             });
         }
         ;
     }
 }
            /// <summary>
            /// Perform image area formats redactions
            /// </summary>
            public static void ImageRedaction()
            {
                //ExStart:ImageAreaRedaction_19.3
                using (Document doc = Redactor.Load(Common.MapSourceFilePath(FilePath)))
                {
                    //Define the position on image
                    System.Drawing.Point samplePoint = new System.Drawing.Point(516, 311);

                    //Define the size of the area which need to be redacted
                    System.Drawing.Size sampleSize = new System.Drawing.Size(170, 35);

                    //Perform redaction
                    RedactionSummary result = doc.RedactWith(new ImageAreaRedaction(samplePoint,
                                                                                    new RegionReplacementOptions(System.Drawing.Color.Blue, sampleSize)));
                    if (result.Status != RedactionStatus.Failed)
                    {
                        //The redacted output will save as PDF
                        doc.Save();
                    }
                    ;
                }
                //ExEnd:ImageAreaRedaction_19.3
            }
        /// <summary>
        /// Shows how to use library in licensed mode using Dynabic.Metered account
        /// </summary>
        public static void UseDynabicMeteredAccount()
        {
            // initialize Metered API
            Metered metered = new Metered();

            // set-up credentials
            metered.SetMeteredKey(PublicKey, PrivateKey);

            // do some work:

            // Load Word document
            using (Document doc = Redactor.Load(Common.MapSourceFilePath(Conversion_Control_FilePath)))
            {
                // Do some redaction
                RedactionSummary result = doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Red)));

                // and get consumption quantity
                decimal consumptionQuantitiy = GroupDocs.Redaction.Metered.GetConsumptionQuantity();

                // get consumption credit (Supported since version 19.5)
                decimal consumptionCredit = GroupDocs.Redaction.Metered.GetConsumptionCredit();
            }
        }