How to release original file

How to release original file

Forum member · May 19, 2010
Hello. We are going to use your Rasterizer class for converting pdf-files into images. We need to delete original pdf-file after converting. Rasterizer doesn't implement IDisposable interface and doesn't contain method (like 'Close()') which allows to release resources. How can we release original file after converting. Thank you in advance.

Re: How to release original file

Forum member · May 19, 2010
I forgot to mention that we are using PDFRasterizer class for x64 platform (DynamicPDF.Rasterizer.35.x64.dll)

Re: How to release original file

Support · May 19, 2010
Hello, Yes, you cannot delete the file immediately after creating the image when using the Rasterizer. However you can do this by getting the file data and create images using the data. You can delete the file after reading the data into memory. Below is a sample code. FileStream fileStream = new FileStream(@"C:\Temp\Test.pdf", FileMode.Open); byte[] pdfData = new byte[fileStream.Length]; BinaryReader reader = new BinaryReader(fileStream); reader.Read(pdfData, 0, (int)fileStream.Length); reader.Close(); //You can delete the file File.Delete(@"C:\Temp\Test.pdf"); //Use the Data for the Rasterizer. InputPdf pdf = new InputPdf(pdfData); PdfRasterizer rasterizer = new PdfRasterizer(pdf); Thanks, ceTe Software Support Team.

Re: How to release original file

Forum member · May 20, 2010
Thank you very much for your help.

Re: How to release original file

Forum member · Oct 26, 2010
I ran into a simular issue with the file resource not being released properly. This solution got me most of the way there, but be sure to also call "fileStream.Close();" after using the PdfRasterizer object and before doing any more file operations. Honestly, I'd consider this a bug if the PdfRasterizer constructor will take a file and not release the resource when it's done, or give the developer control of when to release it.