←Select platform

RedactionOptions Property

Summary

Redaction options to use when this document is viewed or converted.

Syntax
C#
C++/CLI
Python
public DocumentRedactionOptions RedactionOptions {get; set;} 
public:  
   property DocumentRedactionOptions^ RedactionOptions 
   { 
      DocumentRedactionOptions^ get() 
      void set(DocumentRedactionOptions^ value) 
   } 
RedactionOptions # get and set (DocumentAnnotations) 

Property Value

The redaction options to use when this document is viewed or converted. The default value is null.

Remarks

The default value of null instructs the DocumentViewer and DocumentConverter to not perform any special processing for the annotation objects in the pages of this LEADDocument during viewing or converting.

To apply the annotations, set a new instance of DocumentRedactionOptions in RedactionOptions and modify its options for the desired operations.

For more information, refer to Document View and Convert Redaction.

Example

This example will load a PDF document, then dynamically apply redactions to any word containing "leadtools" found, and save the results back into an external PDF.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public void DocumentRedactionExample() 
{ 
   // AnnotationsRedactionOptions redactionOptions = new AnnotationsRedactionOptions(); 
   var cache = new FileCache(); 
   cache.CacheDirectory = @"c:\cache-dir"; 
 
   using (var documentConverter = new DocumentConverter()) 
   { 
 
      // Load a PDF filed 
      var loadDocumentOptions = new LoadDocumentOptions(); 
      loadDocumentOptions.Cache = cache; 
      using (LEADDocument document = DocumentFactory.LoadFromUri(new Uri("http://demo.leadtools.com/images/pdf/leadtools.pdf"), loadDocumentOptions)) 
      { 
         // Convert to PDF using default options 
         string outFileName = Path.Combine(LEAD_VARS.ImagesDir, "no-redaction.pdf"); 
         DocumentRedactConvert(documentConverter, document, DocumentFormat.Pdf, outFileName); 
 
         // Open the converted document no-redaction.pdf, notice that it resembles the original document 
 
         // We will use DocumentPageText to dynamically find the location of all words containing "leadtools" 
 
         document.IsReadOnly = false; 
         const string toRedact = "leadtools"; 
         DocumentPage documentPage = document.Pages[0]; 
         DocumentPageText pageText = documentPage.GetText(); 
         pageText.BuildWords(); 
 
         AnnContainer container = documentPage.GetAnnotations(true); 
         foreach (DocumentWord word in pageText.Words) 
         { 
            // Find if the word is ours 
            if (word.Value.Contains(toRedact)) 
            { 
               // Yes, redact it 
               var annRedactionObject = new AnnRedactionObject(); 
               annRedactionObject.Rect = word.Bounds; 
               container.Children.Add(annRedactionObject); 
            } 
         } 
 
         // Set the container into the page 
         documentPage.SetAnnotations(container); 
 
         // Set the redaction options 
         // AnnotationRedactionOptions & ConvertRedactionOptions reference 
         document.Annotations.RedactionOptions = new DocumentRedactionOptions(); 
         // ViewRedactionOptions & AnnotationsRedactionOptions reference 
         document.Annotations.RedactionOptions.ViewOptions.Mode = DocumentRedactionMode.Apply; 
         document.Annotations.RedactionOptions.ViewOptions.ReplaceCharacter = '*'; 
         document.Annotations.RedactionOptions.ConvertOptions.Mode = DocumentRedactionMode.Apply; 
         document.Annotations.RedactionOptions.ConvertOptions.ReplaceCharacter = '*'; 
 
         document.IsReadOnly = true; 
 
         // Convert again, the result should have all instance of "leadtools" in the first page and replaced with * 
         outFileName = Path.Combine(LEAD_VARS.ImagesDir, "redacted.pdf"); 
         DocumentRedactConvert(documentConverter, document, DocumentFormat.Pdf, outFileName); 
      } 
   } 
} 
 
private static void DocumentRedactConvert(DocumentConverter documentConverter, LEADDocument document, DocumentFormat documentFormat, string outFileName) 
{ 
   var jobData = new DocumentConverterJobData(); 
   jobData.Document = document; 
   jobData.DocumentFormat = documentFormat; 
   jobData.RasterImageFormat = RasterImageFormat.Unknown; 
   jobData.OutputDocumentFileName = outFileName; 
 
   DocumentConverterJob job = documentConverter.Jobs.CreateJob(jobData); 
   documentConverter.Jobs.RunJob(job); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.4.21
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.