LEADTOOLS Support
Document
Document SDK Examples
How To: Clear Filled-Out Forms Used as Master Forms Templates
#1
Posted
:
Wednesday, June 7, 2017 12:48:07 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Sometimes, when creating a master form template, a blank copy of a form can be inaccessible. However, it's recommended to use blank forms when creating templates to prevent the forms engine from improperly identifying the filled-in information on the forms as unique attributes. This code snippet shows how a master form which has been filled in can be blanked out by replacing the contents of the form fields with a solid color. As most forms are binarized into black text on a white backdrop, this changes the blanked out fields to be white as well.
The parameters passed in are the path to the image file (in tif format) of the master form image, and the xmlFile describing where the form field locations are. Note it may be necessary to regenerate the BIN file after performing this to accommodate changes to the form from which the unique attributes are determined.
Code:
public static void BlankFilledForm(string imageFile, string xmlFile)
{
using (RasterCodecs codecs = new RasterCodecs())
{
FormProcessingEngine engine = new FormProcessingEngine();
engine.LoadFields(xmlFile);
FormPages formFields = engine.Pages;
RasterImage image = codecs.Load(imageFile, 0, CodecsLoadByteOrder.Bgr, 1, -1);
for (int i = 0; i < image.PageCount; i++)
{
image.Page = i + 1;
FormPage page = formFields[0];
LogicalRectangle rr = page[0].Bounds;
LeadRect lr = rr.ToRectangle(image.GetImageWidthDpi(true), image.GetImageHeightDpi(true));
image.SetRegion(null, new RasterRegion(lr), RasterRegionCombineMode.Set);
for (int j = 1; j < page.Count; j++)
{
rr = page[j].Bounds;
lr = rr.ToRectangle(image.GetImageWidthDpi(true), image.GetImageHeightDpi(true));
image.SetRegion(null, new RasterRegion(lr), RasterRegionCombineMode.Or);
}
FillCommand fc = new FillCommand();
fc.Color = RasterColor.White;
fc.Run(image);
image.MakeRegionEmpty();
}
codecs.Save(image, "blank-" + imageFile, image.OriginalFormat, image.BitsPerPixel);
}
}
This utilizes the LEADTOOLS FillCommand and image regions. For more information on how the FillCommand is used and how the different regions are set, see our documentation on the command and the enumeration.
https://www.leadtools.com/help/leadtools/v19m/dh/l/imageprocessing-fillcommand.htmlhttps://www.leadtools.com/help/leadtools/v19m/dh/l/rasterregioncombinemode.htmlNick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
How To: Clear Filled-Out Forms Used as Master Forms Templates
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.