ExtractImages disposal

When you call ExtractImages on a PdfPage, it returns an array of Disposable Images:

https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfPageBase.html#Syncfusion_Pdf_PdfPageBase_ExtractImages

Who owns these images?  Does the calling application need to Dispose of them?  Or does Syncfusion manage them when you Dispose the parent PDF?


2 Replies

GK Gowthamraj Kumar Syncfusion Team May 30, 2022 01:52 PM UTC

Hi Joshua Busch,


We are checking on this and we will update the further information on June 1st 2022.


Regards,

Gowthamraj K



GK Gowthamraj Kumar Syncfusion Team June 1, 2022 04:58 PM UTC

Hi Joshua Busch,


Yes. The calling application need to dispose the extracted images using Dispose method. Please refer the below code snippet for disposing the image,

Stream stream = new FileStream(@"D:\Data\PDF\HTTP Succinctly.pdf", FileMode.Open);

            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);

          

            Image[] images = null;

 

            for (int i = 0; i < loadedDocument.Pages.Count; i++)

            {

                images = null;

 

                //Get the page

                PdfLoadedPage page = loadedDocument.Pages[i] as PdfLoadedPage;

 

                //Extract images

                images = page.ExtractImages();

              

                for (int j = 0; j < images.Length; j++)

                {

                    //Save the image to memory stream

                    MemoryStream imageStream = new MemoryStream();

                    images[j].Save(imageStream, ImageFormat.Png);

                 

                    //Save the image to local file

                    imageStream.Position = 0;

                    FileStream outStream = System.IO.File.OpenWrite("../../../Test" + i.ToString()+ "_"+j.ToString() + ".png");

                    imageStream.WriteTo(outStream);

                    outStream.Flush();

                    imageStream.Dispose();

                    images[j].Dispose();

                }

            }

 


Please let us know if you need any further assistance in this.



Regards,

Gowthamraj K


Loader.
Up arrow icon