You can use PageAreaRedaction to redact an area of a specific page range from sensitive data in text, images, and annotations. Combine it with PageRangeFilter and PageAreaFilter on ReplacementOptions. This works for PDF and for other formats that support page filters (see Supported document formats). For embedded or standalone images, area coordinates follow the page (or visible) placement of the image.
The following example demonstrates how to apply PageAreaRedaction to the right half of the last page in a PDF document.
constredaction=require('@groupdocs/groupdocs.redaction');constjava=require('java');constColor=java.import('java.awt.Color');constDimension=java.import('java.awt.Dimension');constPoint=java.import('java.awt.Point');constredactor=newredaction.Redactor('Sample.pdf');try{constrx=java.util.regex.Pattern.compile('urna');constoptionsText=newredaction.ReplacementOptions('[redarea]');optionsText.setFilters(newredaction.RedactionFilter[]{newredaction.PageRangeFilter(redaction.PageSeekOrigin.End,0,1),// last page
newredaction.PageAreaFilter(newPoint(300,0),newDimension(300,840))// right half of the page
});constoptionsImg=newredaction.RegionReplacementOptions(Color.RED,newDimension(100,100));constresult=redactor.apply(newredaction.PageAreaRedaction(rx,optionsText,optionsImg));if(result.getStatus()!==redaction.RedactionStatus.Failed){redactor.save();}}finally{redactor.close();}
Sample.pdf is the sample file used in this example. Click here to download it.