Issue disposing of image

Discussions about PDF management.
Post Reply
stammd
Posts: 8
Joined: Sun Oct 16, 2016 4:35 pm

Issue disposing of image

Post by stammd » Wed Nov 09, 2016 12:27 pm

I am using the following code to loop through a number of PDF documents and doing OCR on them. The issue I am having is that the picture is not being disposed and the new picture loaded. It seems to just continually process the first PDF uploaded. In the code below the foreach loops through the PDF files, while the inner for loop goes through each page of the PDF. The issues is that the first PDF document gets re-processed as many times as I have items in the foreach list.

Am I not disposing of the image correctly?

Code: Select all

                            
                            var allBlobs = container.ListBlobs(null, true, BlobListingDetails.All).Cast<CloudBlockBlob>();

                            foreach (CloudBlockBlob item in allBlobs)
                            {
                                if (item.GetType() == typeof(CloudBlockBlob) & item.Name.EndsWith(".pdf"))
                                {
                                    // Read the file (blob) into a MemoryStream for conversion into a GdPicture element
                                    using (MemoryStream memStream = new MemoryStream())
                                    {
                                        item.DownloadToStream(memStream);

                                        // Convert memoryStream of the PDF into GdPicture element
                                        GdPicturePDF picture = new GdPicturePDF();
                                        picture.LoadFromStream(memStream);   

                                         int numPages = picture.GetPageCount();
                                        #region Loop through all the pages in a document
                                        for (int i = 1; i <= numPages; i++)
                                        {
                                           
                                            // Loop through all pages and do OCR
                                          
                                            // Clean up memory and release the GdPictureImage
                                            image.Dispose();
                                            image.ReleaseGdPictureImage(imageId);


                                        }
                                        #endregion

                                        // Done reading all pages so close document
                                        picture.CloseDocument();
                                        picture.Dispose();

                                    }

                                    // Delete the PDF document from Blob storage
                                    item.Delete();
                                    
                                }

                            }
                            

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: Issue disposing of image

Post by Cedric » Wed Nov 09, 2016 12:36 pm

I'm sorry but there is nothing we can do with this code, there is too much missing to tell what could be wrong in it.
I strongly suggest that you open a ticket on the support platform to provide us with a proper code snippet we can run as is for debugging purpose in order to understand what you are exactly doing.

stammd
Posts: 8
Joined: Sun Oct 16, 2016 4:35 pm

Re: Issue disposing of image

Post by stammd » Fri Nov 11, 2016 4:40 am

The issue was on my file upload to the Azure blob. The code posted above is working as intended. Apologies.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest