Very few individuals like their personal information shared and I guarantee no one likes private information from documents being shared either. Images of financial documents, such as checks, are sent across large companies every day. In a world where anything can be uploaded to the internet and stolen in seconds, you can never be too careful with protecting personal information.
Redaction of personal information, sometimes known as “Sanitization”, is the blacking out or deletion of text in a document. It is intended to allow the selective disclosure of information in a document while keeping other parts of the document secret. When stored information is modified or erased, some or all of the data still remain in storage. This may be an accident of design, where the underlying storage mechanism still allows information to be read, despite its nominal erasure. The general term for this problem is “data remanence”. In some contexts, redaction typically refers to countering the data remanence problem.
This blog post will demonstrate how the LEADTOOLS MICR SDK can detect the MICR font on a check, and then redact it to hide private financial information using the Annotations SDK.
Create a method called DetactRedact(string file)
. This method will search every file found in a given directory, and then detect if a Magnetic Ink Character Recognition (MICR) zone is found using the MICRCodeDetectionCommand Class
. If a MICR zone is found, it will redact the coordinates of the zone hiding it from view.
First, set up the AnnContainer
. This container will eventually be what is covering the private information on the check.
// Initialize the rendering engine
AnnWinFormsRenderingEngine renderingEngine = new AnnWinFormsRenderingEngine();
string dir = Path.Combine(Path.GetDirectoryName(file), "Redacted");
// Check if directory exists, if not create it.
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string outFile = Path.Combine(dir, Path.GetFileNameWithoutExtension(file) + "_redacted.tif");
// Get total pages found in image and look for MICR zone
int totalPages = codecs.GetTotalPages(file);
for (int i = 1; i <= totalPages; i++)
using (RasterImage image = codecs.Load(file, i)){
}
Next, add the code to detect both MICR zone and CMC7 zones found on checks. This code will go inside the using
statement from above.
MICRCodeDetectionCommand detectionCommand = new MICRCodeDetectionCommand();
detectionCommand.Run(image);
if (detectionCommand.MICRZone != LeadRect.Empty && detectionCommand.MICRZone.Width > 0 && detectionCommand.MICRZone.Height > 0)
{
AnnRedactionObject redaction = new AnnRedactionObject
{
Rect = container.Mapper.RectToContainerCoordinates(detectionCommand.MICRZone.ToLeadRectD()),
Fill = AnnSolidColorBrush.Create("Black")
};
container.Children.Add(redaction);
}
CMC7CodeDetectionCommand cmc7DetectionCommand = new CMC7CodeDetectionCommand();
cmc7DetectionCommand.Run(image);
if (cmc7DetectionCommand.CMC7Zone != LeadRect.Empty && cmc7DetectionCommand.CMC7Zone.Width > 0 && cmc7DetectionCommand.CMC7Zone.Height > 0)
{
AnnRedactionObject redaction = new AnnRedactionObject
{
Rect = container.Mapper.RectToContainerCoordinates(cmc7DetectionCommand.CMC7Zone.ToLeadRectD()),
Fill = AnnSolidColorBrush.Create("Black")
};
container.Children.Add(redaction);
}
Lastly, you will need to burn the redaction object into the image and then save the image. The following code will go after the using
statement.
var img = renderingEngine.RenderOnImage(container, image.Clone());
codecs.Save(img, outFile, RasterImageFormat.TifJpeg411, 24, 1, 1, 1, CodecsSavePageMode.Append);
Now if you look in the output folder, there will be a black redaction stripe covering the CMC7/MICR zones. Burning the annotaions changes the pixel data in the image ensuring that the information that has been covered cannot be retrieved anymore. It does not create another layer in the image.
Before
After
Download Project
To test this with the latest version of LEADTOOLS, download the free 60 day evaluation straight from our site. If you have any comments or questions regarding this, feel free to comment on this post or contact our Support department at support@leadtools.com.