PixTools:  Tips & Techniques

Tip1:  Getting a PatchCode separator to work.
 
Using a patchcode is frequently one of the easiest methods for separating batches or documents.  Patchcodes can typically be reliably detected at a > 98% detection rate.  To use a patchcode separator, first declare a patchcode separator object:

 

PatchcodeJobSeparator separator = new PatchcodeJobSeparator();

Then add the patchcode types you want to detect:

 

 separator.Types.Add(PixBarcodeType.Patch_I);
 separator.Types.Add(PixBarcodeType.Patch_II);


Finally, you can detect the patchcode in the PageScan event:

 

        private void scanner_OnPage(object sender, PageEventArgs e)
        {
            bool bpatch = ps.Detect(e.Page);
     ...
        }


Tip2:  Determining Valid Image Properties

 

When trying to save an image, it's fairly common to get an error message about "PixInvalidFileFormatException".  This error is typically caused by an invalid combination of imaging options.  To see the valid combinations you can use the FileTypeChoices tool.  To use the tool:

 

      a.  Start the FileTypeChoices tool
      b.  In the File Format Window, select an image type
      c.  In the Color Format Window, select a color format
      d.  In the Compression Window, the compression types are listed

 

You can then choose a combination of valid options for the image type.

 


Tip3:  Deleting the Last Page in a Multipage Document

 

Often the last page in a document is either blank or contains some useless information.  The following code segment shows how to delete the last page in a multipage document:

 

 PixDocument document = new PixDocument();
 ....
 int lastpage = document.Children.Count - 1;
 document.Remove(document.Children[lastpage]);

 

Tip4: Scanning and Saving Images to a Multipage Document

 

Scanned documents can be saved either as single pages, or stored in a multipage document.  Here is an overview on how to use PixDocument to create a multipage document:

 

        PixDocument document = new PixDocument();
           ....
        private void scanner_OnPage(object sender, PageEventArgs e)  // page scan event
        {
            document.Add(e.Page);
            ...
        }
        private void buttonMerge(object sender, EventArgs e)
        {
             string sfilename = "c:\\Test12345.tif";
             if (File.Exists(sfilename))
                 File.Delete(sfilename);
             PixImageStorage.Create(sfilename, PixFileType.Tiff);
             PixImageStorage storage = PixImageStorage.Open(sfilename);
             for (int index=0; index<document.Children.Count; index++)            
             {
                   // the compression settings change with differt types of images
                   PixCompressionSettings c = new PixCompressionSettings(ColorFormat.BlackWhite0, PixCompression.G4);                      
                   storage.Append(((PixImageNode)document.Children[index]).Image, c);
             }
        }

 

Tip5: Document Reader Driver

 

When images already exist, you can read the images from disk by using the ReadFileDriver:

 

     ReadFileDriver driver = new ReadFileDriver();
     SimpleScanner scanner = new SimpleScanner(driver);
     scanner.OnPage += new EventHandler<PageEventArgs>(scanner_OnPage);
     foreach (FileInfo f in files)
     {
          try
          {
               driver.OpenFile(f.FullName);
               scanner.Scan();
          }
          catch (PixException er)
          {
               MessageBox.Show(er.Message);
          }
     }