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

Unable to Convert Pdf to Png Using Ghostscript.Net Visual Studio 2022 #101

Open
longgreybeard opened this issue May 28, 2022 · 2 comments
Open

Comments

@longgreybeard
Copy link

Hello everyone and thanks for the help in advance. I am using GhostScript.Net to convert Pdf files to Png images. This has worked perfectly fine using Visual Studio 2019 on a Windows 10 OS. However, when I moved to VS 2022 I continue to receive an error "System.NullReferenceException" when trying to save the Png, Here is my code:

` using (var rasterizer = new GhostscriptRasterizer()) //create an instance for GhostscriptRasterizer
{

         string fileName = Path.GetFileNameWithoutExtension(inputFile);

         rasterizer.Open(inputFile); //opens the PDF file for rasterizing
         SendEmail sendEmail9 = new SendEmail("Page Count", rasterizer.PageCount.ToString(), "");

         //set the output image(png's) complete path
         var outputPNGPath = @"E:\out.png";

         //converts the PDF pages to png's 
         var pdf2PNG = rasterizer.GetPage(100, 1);

         //save the png's

         pdf2PNG.Save(outputPNGPath, ImageFormat.Png);

     }

pdf2PNG.Save(outputPNGPath, ImageFormat.Png); throws the error. I have installed gsdll64.dll, located in C:\Program Files\gs\gs9.56.1\bin. I'm not sure where to go from here Any help would be appreciated.`

@adam-of-barot
Copy link

I'm also having the same issue. GetPage returns a null value.
I'm using the 32-bit version of GhostScript (C:\Program Files (x86)\gs\gs9.56.1\bin)

@KeithVinson
Copy link

Try adding this line to your code:
rasterizer.CustomSwitches.Add("-dNEWPDF=false");
workaround provided in another Issue...

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

3 participants