Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
System.Runtime.InteropServices.SEHException |
Post Reply |
Author | |
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
Posted: 30 Apr 18 at 8:24PM |
Hi,
if TFrost is right regarding the memory consumption it could be good to calculate the sizes of your pdf-documents... make a break from time to time with a Free... keep the actual page number in mind... and start new with the last page number? |
|
Cheers,
Ingo |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
You have not said anything about the size of your PDFs or the size of the images, or how uniform their sizes are. The images may need to pass through an intermediate (uncompressed) BMP on the way to their save format, and multiple copies may also be in memory. The fact that freeing the image list improves matters implies that the lack of memory is genuine. 500MB of free memory is by no means a huge amount, and your problem may be caused by memory fragmentation even when the total shown by Task Manager appears to be large enough (Process Explorer might show more detail). I would recommend increasing your virtual memory space to a few GB to see of this solves the problem. I do not use .Net so I have no idea how to deal with memory fragmentation in this environment, but it is a common problem when dealing with large bitmaps in a limited memory pool.
|
|
imsudheer
Beginner Joined: 27 Apr 18 Status: Offline Points: 9 |
Post Options
Thanks(0)
|
I tried the DA-functions, still the same issue.
My question is, even though I have released the image and imagelist after the use and removing the document from the Library, why I am getting the "Out of memory" exception. Release resources is not working? Am I missing anything?
|
|
imsudheer
Beginner Joined: 27 Apr 18 Status: Offline Points: 9 |
Post Options
Thanks(0)
|
Thanks for the reply.
My code is referred from the same kb-sample you mentioned. I have added the code to remove the each image file from memory after saving as pdfLibrary.SaveImageListItemDataToFile(il, k, 0, Path.Combine(path, filename)); pdfLibrary.ReleaseImage(imageIndex); I see there is some improvement in the process, as I am able to extract around 45 files without "Outofmemory" exception, earlier I used to get the same exception only for 10 files. So it got better after the above change. I haven't tried the DA-functions yet, will try and post the result.
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Perhaps this kb-sample can help?
http://www.debenu.com/kb/extract-images-from-pdf-files-as-the-appropriate-image-type/ What about trying the DA-functions for your needs using less memory? http://www.debenu.com/docs/pdf_library_reference/ImageHandling.php |
|
Cheers,
Ingo |
|
imsudheer
Beginner Joined: 27 Apr 18 Status: Offline Points: 9 |
Post Options
Thanks(0)
|
Yes, what you mentioned about the page count part. I will take care of that.
And I have tried the "ReleaseImageList" option, but im still getting the Out of memory exception.
|
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
I think you need to add ReleaseImageList. Also your main loop is described in the comments as iterating through the pages, but in this case you should first find the page count, not the image count. Unless you already know that there is guaranteed to be one and only one image per page.
|
|
imsudheer
Beginner Joined: 27 Apr 18 Status: Offline Points: 9 |
Post Options
Thanks(0)
|
I just tried the same code with ActiveX DLL, here it is throwing "Out of memory" exception as below
at FileProcessor.ImageExtractor.ExtractImages(String fileName, String outPath) in C:\FileProcessor\ImageExtractor.cs:line 51 1506700 [1] ERROR FileProcessor.ImageExtractor (null) - Error Message: Out of memory System.Runtime.InteropServices.COMException (0x8000FFFF): Out of memory at DebenuPDFLibraryAX1511.IPDFLibrary.FindImages() But I am removing the document after the use in loop...Im not sure what is missing here And what is the advantages of Active X DLL compared to "DLL" Version?
|
|
imsudheer
Beginner Joined: 27 Apr 18 Status: Offline Points: 9 |
Post Options
Thanks(0)
|
Hi Ingo,
Thanks for the reply. Files are not encrypted. See my code below. foreach (var filename in Directory.GetFiles(searchPath, "*.pdf", SearchOption.TopDirectoryOnly)) { Console.WriteLine("Extracting images from {0}", System.IO.Path.GetFileName(filename)); ImageExtractor.ExtractImages(filename, outputPath); Console.WriteLine("Extracting images from {0} is completed.", System.IO.Path.GetFileName(filename)); } public static void ExtractImages(string fileName, string outPath) { log4net.Config.BasicConfigurator.Configure(); log4net.ILog log = log4net.LogManager.GetLogger(typeof(ImageExtractor)); // Check to see if the library has been successfully unlocked if (pdfLibrary.Unlocked() == 1) { try { int DocumentID = pdfLibrary.LoadFromFile(fileName, ""); pdfLibrary.SelectDocument(DocumentID); int images = pdfLibrary.FindImages(); string numberOfImages = Convert.ToString(images); string filename = ""; // Iterate through each page for (int i = 1; i <= images; i++) { // Select current page pdfLibrary.SelectPage(i); // Get list of images on the page int il = pdfLibrary.GetPageImageList(0); // Count number of images in the list int ic = pdfLibrary.GetImageListCount(il); for (int k = 1; k <= ic; k++) { // Iterate through each image and get the // image type and image ID int it = pdfLibrary.GetImageListItemIntProperty(il, k, 400); int gid = pdfLibrary.GetImageListItemIntProperty(il, k, 405); // Choose the approrpriate file extenion based on // the returned image type switch (it) { case 1: filename = "image-" + Convert.ToString(gid) + "-" + k + ".jpg"; break; case 2: filename = "image-" + Convert.ToString(gid) + "-" + k + ".bmp"; break; case 3: filename = "image-" + Convert.ToString(gid) + "-" + k + ".tif"; break; case 4: filename = "image-" + Convert.ToString(gid) + "-" + k + ".png"; break; default: Console.WriteLine("Unknown image type" + it); break; } // Creating an image directory string path = outPath + @"\" + Path.GetFileNameWithoutExtension(fileName); if (Directory.Exists(path) == false) Directory.CreateDirectory(path); // Save the selected image to disk pdfLibrary.SaveImageListItemDataToFile(il, k, 0, Path.Combine(path, filename)); Console.WriteLine("Images of the file " + fileName + " saved successfully"); } } // Remove the document from memory pdfLibrary.RemoveDocument(DocumentID); File.Delete(fileName); } catch (Exception ex) { log.Error("Error Message: " + ex.Message.ToString(), ex); Console.WriteLine("Error occured in file " + fileName); Console.WriteLine(ex); } } Thanks in Advance |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Imsudheer,
you should better post a longer code snippet. Perhaps the error raises while using the mentioned function but the reason of the error is another one? I think you're reading the pdf-content of a directory in a list and then you're working in a loop. Loading each file and do the extractions. Perhaps some files are encrypted? You should do a decryption before working on a pdf. Did you do a free after each pdf? There could be many reasons for such a common error... So better posting a code snippet ;-) Cheers and welcome here, Ingo |
|
Cheers,
Ingo |
|
imsudheer
Beginner Joined: 27 Apr 18 Status: Offline Points: 9 |
Post Options
Thanks(0)
|
Hello All,
I am running the Quick PDF Library to extract the images from pdf files in a loop. The total pdf's are around 200. But I am getting the following exception after processing of 10 files. I dont see any error with the files, because if I run the code with specific files, I dont see any error. And I verified the available RAM at the time of exception. Which is around 500 ( stand by RAM) and 200mb normal RAM. So I dont see this as an issue with RAM. This is the error below. 1188785 [1] ERROR FileProcessor.ImageExtractor (null) - Error Message: External component has thrown an exception. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at DebenuPDFLibraryDLL1511.PDFLibrary.GetImageListItemIntProperty(Int32 Image ListID, Int32 ImageIndex, Int32 PropertyID) in C:\FileProcessor\DebenuPDFLibraryDLL1511.cs:line 6032 at FileProcessor.ImageExtractor.ExtractImages(String fileName, String outPath ) in C:\CodeBase\FileProcessor\FileProcessor\ImageExtractor.cs:line 72 1224191 [1] ERROR FileProcessor.ImageExtractor (null) - Error Message: External component has thrown an exception. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at DebenuPDFLibraryDLL1511.PDFLibrary.FindImages() in C:\FileProcessor\DebenuPDFLibraryDLL1511.cs:line 5053 at FileProcessor.ImageExtractor.ExtractImages(String fileName, String outPath ) in C:\FileProcessor\ImageExtractor.cs:line 51 Thanks in Advance..
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store