logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Elm  
#1 Posted : Friday, October 14, 2016 8:45:05 AM(UTC)
Elm

Rank: Member

Groups: Registered
Joined: 5/30/2016(UTC)
Posts: 14
France

Thanks: 4 times
Hi,

I use pdfium to extract images from PDF pages (among other things)
I have this file of 100 something pages.
The first 50 pages extract correctly and then suddently the folowing ones are empty.

My code is like this :
Code:

            Int32 dpi = 96;

            using (var doc = Patagames.Pdf.Net.PdfDocument.Load(filePath))
            {
                int i = 0;
                foreach (var page in doc.Pages)
                {
                    i++;

                    int width = (int)(page.Width / 72.0 * dpi);
                    int height = (int)(page.Height / 72.0 * dpi);

                    using (var bitmap = new PdfBitmap(width, height, true))
                    {
                        bitmap.FillRect(0, 0, width, height, Color.White);
                        page.Render(bitmap, 0, 0, width, height, Patagames.Pdf.Enums.PageRotate.Normal, Patagames.Pdf.Enums.RenderFlags.FPDF_LCD_TEXT);

                        bitmap.Image.Save($@"d:\Image{i}.png", ImageFormat.Png);

                        Console.WriteLine($"Page {i} : {width}x{height} - {MS.Length}");
                    }
                }
            }


The width and height for those pages are correctly detected but the output is a blank PNG.
From a human point of vue, those pages seems no different than the others.
I have tested another extraction API and the images are correctly processed.

I can provide the PDF but only via private email as it contains customer information.
Paul Rayman  
#2 Posted : Saturday, October 15, 2016 7:47:28 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
This issue occurs due to out of memory in your 32 bit environment.
You need to add the page.Dispose() statement before ending the foreach() iteration.

Code:

foreach (var page in doc.Pages)
{
    ...
    page.Dispose();
}

Edited by user Saturday, October 15, 2016 8:07:12 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Paul Rayman for this useful post.
Elm on 10/16/2016(UTC)
Elm  
#3 Posted : Sunday, October 16, 2016 1:22:13 AM(UTC)
Elm

Rank: Member

Groups: Registered
Joined: 5/30/2016(UTC)
Posts: 14
France

Thanks: 4 times
Originally Posted by: Paul Rayman Go to Quoted Post
This issue occurs due to out of memory in your 32 bit environment.
You need to add the page.Dispose() statement before ending the foreach() iteration.

Code:

foreach (var page in doc.Pages)
{
    ...
    page.Dispose();
}


Thanks Paul, indeed it does work like that
Users browsing this topic
Guest
Forum Jump  
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.