/// <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> /// 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> /// 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> /// 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(); } }
/// <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 }