How to create a script to Automatically Remove and Replace Information from your Documents

You can use scripts to redact information from recognized text:

1. Replace information in a document.
To do so, call the IDocumentToIndexPage::ReplaceTextOnPage( what, with, ignoreCase ) method in the indexing script.
For example, if you want to replace the text "SampleText" with "ChangedText" throughout the whole document regardless of case, add the following script:

 //JScript
 for( var p = 0, pc = this.Pages.Count; p < pc; p++){
     var page = this.Pages.Item(p);
         page.ReplaceTextOnPage( 'SampleText', 'ChangedText', true);
 }
 this.SkipManualIndexing = true;

Important! Line breaks (\n) and tabs (\t) cannot be used as "SampleText" and "ChangedText" arguments.

2. Hide this information in detected blocks.
To do so, call the RedactRegion method for the selected block in the indexing script.
Note. This method is not suitable for barcode blocks.
To edit all detected text blocks in a document, add the following sample code to your script:

 //JScript
 for( var p = 0, pc = this.Pages.Count; p < pc; p++){
   var page = this.Pages.Item(p);
   for(var tb = 0, tbc = page.TextBlocks.Count; tb < tbc; tb++){
       var textBlock = page.TextBlocks.Item(tb);
       page.RedactRegion(textBlock.Region);
   }
 }
 this.SkipManualIndexing = true;

3. Edit index fields.
To do so, call the RedactRegion method for the selected index field in the IndexingFinished script.
To edit all index fields for the selected document type, add the following sample code to your script:

 //JScript
 var pagesCount = this.DocumentPages.Count;
 for( var a = 0, ac = this.Attributes.Count; a < ac; a++) {
    var attribute = this.Attributes.Item(a);
    var pageIndex = attribute.PageIndex;
    if( pageIndex >= 0 && pageIndex < pagesCount ){
        this.DocumentPages.Item(pageIndex).RedactAttribute(attribute);
    }
 }

3/26/2024 1:49:49 PM

Please leave your feedback about this article

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.