ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit). Tested with Ghostscript versions < 10.
https://ghostscript.com
GNU Affero General Public License v3.0
403 stars 155 forks source link

Converting PDF pages to images (new PDF interpreter problem) #102

Open Mertbaykar opened 2 years ago

Mertbaykar commented 2 years ago

Hello, i use GhostScript.Net to convert PDF pages to images. I have the following code to achieve this:

public static List<string> GetPDFPageText(Stream pdfStream, string dataPath)
    {

        try
        {
            int dpi = 100;
            GhostscriptVersionInfo lastInstalledVersion =
           GhostscriptVersionInfo.GetLastInstalledVersion(
                   GhostscriptLicense.GPL | GhostscriptLicense.AFPL,
                   GhostscriptLicense.GPL);
            List<string> textParagraphs = new List<string>();

            using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
            {
                rasterizer.Open(pdfStream, lastInstalledVersion,false);

                for (int i = 1; i <= rasterizer.PageCount; i++)
                {
                    // here is the problem, pageImage returns null
                    System.Drawing.Image pageImage = rasterizer.GetPage(dpi, i);

                    // rest of code is unrelated to problem..

                }
            }

            return textParagraphs;
        }
        catch (Exception ex)
        {
            throw new Exception("An error occurred.");
        }

    }

I think the new PDF interpreter may have some problems for now since it is new. Image returns null unless i add the following code:

rasterizer.CustomSwitches.Add("-dNEWPDF=false");

It works using old PDF interpreter. I just wanted to let you know about this problem. Thank you in advance.

KeithVinson commented 2 years ago

Yes, I ran into the same problem (the returned image is always null). The work around also worked for me...