Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mertbaykar opened this issue May 29, 2022 · 1 comment
Open

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

Mertbaykar opened this issue May 29, 2022 · 1 comment

Comments

@Mertbaykar
Copy link

Mertbaykar commented May 29, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants