LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW-TO: Splitting an Existing File into Multiple Files using Patch Codes
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Patch codes are typically used to indicate to a TWAIN device that a specific action is to be taken with certain pages in a document being scanned, such as organization or classification. However, if a document has already been scanned or only ever existed as a digital copy, LEADTOOLs can still process the patch codes. The code snippet below show how to use the LEADTOOLS barcode reader to divide a document into multiple output files based on where patch codes are detected.
BarcodeReaderCode: public static void SplitPatchDocument(string inputFile)
{
RasterCodecs codecs = new RasterCodecs();
codecs.Options.Load.AllPages = true;
BarcodeReader reader = new BarcodeEngine().Reader;
RasterImage image = codecs.Load(inputFile);
int startPage = 1;
int sectionNumber = 1;
for (int i = 0; i < image.PageCount; i++)
{
image.Page = i + 1;
BarcodeData[] data = reader.ReadBarcodes(image, LeadRect.Empty, 0, new BarcodeSymbology[] { BarcodeSymbology.PatchCode });
if (data.Length > 0)
{
string filename = string.Format("split_{0}.tif", sectionNumber);
codecs.Save(image, filename, RasterImageFormat.Tif, 0, startPage, image.Page, 1, CodecsSavePageMode.Overwrite);
startPage = image.Page + 1;
sectionNumber++;
}
}
if (startPage <= image.PageCount)
{
string filename = string.Format("split_{0}.tif", sectionNumber);
codecs.Save(image, filename, RasterImageFormat.Tif, 0, startPage, image.PageCount, 1, CodecsSavePageMode.Overwrite);
}
}
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.

LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW-TO: Splitting an Existing File into Multiple Files using Patch Codes
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.