Page 1 of 1

ImageCollection Issues

Posted: Fri Dec 05, 2008 11:19 pm
by alphadog
I have some code that opens a multi-page TIFF (tFile = new TiffFile(e.FullPath)) and then iterates through the pages to split, based on blank page detection, into individual PDFs .

This code below (tested with the trial component):
a) won't save at col.Save(aPath, pdf). aPath is correct. No PDF is produced. Is it because it is a trial?
b) craps out the SetImage at the start of the loop (img.SetImage(pg.GetImage())) after the first save-and-clear is called, with a System.NullReferenceException. If I comment out the Clear() just after the red line, I don't get the exception. I suspect that when I col.Add(img) to col, and then later call col.Clear(), I end up disposing the img object? If so, how should I get the TIFF pages into col "by copy"?

Code: Select all

            TiffPageCollection pgs = tFile.Pages;
            if (pgs.Count == 0)
                logWriter.WriteLine("-> No pages in multi-tiff. Done.");
                if (tFile != null)

            VintasoftImage img = new VintasoftImage(pgs[0].GetImage()); 
            ImageCollection col = new ImageCollection(); // will hold collection of processed TIFFs
            PdfEncoder pdf = new PdfEncoder(true, 80);
            int pgIdx = 0;
            int pdfIdx = 1;
            float blankThreshold = float.Parse(ConfigurationSettings.AppSettings["blankThreshold"]);
            string aPath = "";
            // begin processing
            foreach (TiffPage pg in pgs)
                catch (Exception err)
                    if (tFile != null)

                if (img.IsBlank(blankThreshold))
                {   // cut it up
                    logWriter.WriteLine("-> Blank page at position: " + pgIdx);
                    if (col.Count > 0)
                    {   // save it if there meat in the collection 
                        aPath = e.FullPath.Replace(".", "_") + "_" + pdfIdx + ".pdf";
                        logWriter.WriteLine("-> Creating PDF with " + col.Count + " pages.");
                        col.Save(aPath, pdf);
                        logWriter.WriteLine("-> PDF saved at: " + aPath);
                {   // process, clean and add
                    img.Deskew(BorderColor.AutoDetect, 5, 5);
                    //img.Despeckle(8, 25, 30, 400);


Re: ImageCollection Issues

Posted: Tue Dec 09, 2008 5:02 pm
by Alex

-> would not save at col.Save(aPath, pdf). aPath is correct. No PDF is produced. Is it because it is a trial?

No, it is not a limitation of the evaluation version. Your code has logical mistake. The Add method of the ImageCollection class does not copies image objects so you must store all non blank images in memory or add images one by one to a file on a disk.

Please read the "Getting Started" section in the documentation of the product.

Best regards, Alexander