Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm converting multiple page PDF files to JPG and saving to disk using ghostscript.net. I am then adding them to a stackpanel (vertical orientation) on a canvas inside a ScrollViewer. This works well for small documents however larger documents only work up to about the 10th page at 500 dpi. Anything more than that and they don't seem to appear in my stackpanel. However, as I decrease the DPI I can get more pages to appear, but they are of course smaller which is not desirable.

I am doing it inside a for loop and at first thought it was rolling through the loop too fast and the writting to the hard drive was too slow, so I stuck some thread.sleep(2000) in the loop to try and slow it down but this had no affect on the amount of pages that appeared.

I am not sure, and cant find any documentation to indicate if this is an issue with how much information can appear in a stackpannel, or if there is a limit on ghostscript rasterization or rasterization.getpage()

What I have tried:

C#
<pre>            using (var rasterizer = new GhostscriptRasterizer()) //create an instance for GhostscriptRasterizer
            {
                //opens the PDF file for rasterizing
                string mydocpath = myDir; //Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                rasterizer.Open("test.pdf");
                var rasterimg = new GhostscriptRasterizer();
                rasterimg.("test.pdf");
                double imgHeight = 0;
                for (int i = 1; i <= rasterizer.PageCount; i++)
                {
                    rasterimg.Open("test.pdf");
                    var img = rasterizer.GetPage(400, 400, i);
                    rasterimg.Dispose();
                    img.Save(mydocpath + "/test_"+i+".jpg", ImageFormat.Jpeg);
                    string imgPath = mydocpath + "/test_" + i + ".jpg";
                    Image myImage = new Image();
                    myImage.Name = "test_" + i;
                    myImage.Source = new BitmapImage(new Uri("File://" + imgPath));
                    pdfcanvas.Children.Add(myImage);
                    imgHeight = imgHeight + myImage.Source.Height;
                    if (pdfcanvas1.Width <= myImage.Source.Width)
                        {
                            pdfcanvas1.Width = myImage.Source.Width;
                        }
                }    
                pdfcanvas1.Height = imgHeight;
                
            }
Posted
Comments
Richard Deeming 8-Feb-18 14:29pm    
Why are you calling Open and Dispose on the rasterimg inside the loop? Just open the file once, outside of the loop, and dispose of it after the loop has finished.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900