Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, August 16, 2019 10:56:08 AM(UTC)

Nick  
Nick

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.

BarcodeReader

Code:

      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;

         // iterate over each page in the document
         for (int i = 0; i < image.PageCount; i++)
         {
            image.Page = i + 1;

            // check the page for patch codes
            BarcodeData[] data = reader.ReadBarcodes(image, LeadRect.Empty, 0, new BarcodeSymbology[] { BarcodeSymbology.PatchCode });

            // if a patch code is here, save out this portion of the document
            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);

               // set the page to start the next document section on to be the next page after the patch page to prevent doubles
               startPage = image.Page + 1;

               // increment the iterator for the divided files
               sectionNumber++;
            }
         }

         // finally, save the pages from the last patch page detected to the end of the document
         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.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.037 seconds.