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

GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100 #10

Closed
mehdyh opened this issue Jul 13, 2015 · 12 comments

Comments

@mehdyh
Copy link

mehdyh commented Jul 13, 2015

I occasionally get this exception, any idea about the root cause?

GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100,

stack trace:
Ghostscript.NET.Interpreter.GhostscriptInterpreter.Initialize():47
Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor(GhostscriptVersionInfo version, Boolean fromMemory):55
Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory):47
Ghostscript.NET.Viewer.GhostscriptViewer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory):47
Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory):36

@EricSmekens
Copy link

I have the same error, when I call StartProcessing.

@mehdyh
Copy link
Author

mehdyh commented Oct 22, 2015

Fixed the issue by changing
_rasterizer.Open(mm, lastInstalledVersion, false);
to
_rasterizer.Open(mm, lastInstalledVersion, true);

@JenkaJmenka
Copy link

I'm sorry for my question
I have the same error.
Any ideas how it can be solved?

@jhabjan
Copy link
Contributor

jhabjan commented Dec 14, 2016

Error -100 means that you are passing some bad parameters or you can try mehdymohajery solutoin.

@jhabjan jhabjan closed this as completed Dec 14, 2016
@dherbe
Copy link

dherbe commented Dec 27, 2016

I also got this error and It really wasn't because of bad arguments.
mehdymohajery suggestion worked perfectly.
thanks

mellson added a commit to mellson/ImageProcessor.Plugins.Pdf that referenced this issue May 9, 2018
@csharpner
Copy link

@mehdymohajery what is this lastInstalledVersion? Where/how do I get it?

@cpayne22
Copy link

cpayne22 commented Jun 4, 2018

@csharpner this worked for me:

GhostscriptVersionInfo gsVersionInfo = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);

Source: https://stackoverflow.com/q/26917330/5188

dampee pushed a commit to dampee/ImageProcessor.Plugins.Pdf that referenced this issue Jul 3, 2018
* Use in memory version

As per discussed here ArtifexSoftware/Ghostscript.NET#10

* update last open to use in memory version
@bkwdesign
Copy link

I'm still getting this error and none of the solutions posted above worked. I just finished running the .exe to install Ghostscript to my Windows 10 workstation on C:/Ghostscript

I can see my "last version info" is being detected successfully when I debug:
image

Here's my code snippet that is failing:

    int desired_x_dpi = 96;
    int desired_y_dpi = 96;

   string inputPdfPath = "sample.pdf";

   using (var rasterizer = new GhostscriptRasterizer())
   {
        GhostscriptVersionInfo gsVersionInfo = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);

        byte[] buffer = File.ReadAllBytes(inputPdfPath);
        MemoryStream ms = new MemoryStream(buffer);
               
        rasterizer.Open(ms, gsVersionInfo, true);
   }

@Amonra69
Copy link

Same issue, Solution of @mehdyh doesn't work. I try to setup dll manually but it doesn't work again

            int desired_x_dpi = 96;
            int desired_y_dpi = 96;

            string inputPdfPath = @"C:\image.pdf";
            string outputPath = @"C:\";

            var _lastInstalledVersion = new GhostscriptVersionInfo(Version.Parse("9.53.3"), @"C:\Program Files (x86)\gs\gs9.53.3\bin\gsdll32.dll", @"C:\Program Files (x86)\gs\gs9.53.3\lib\gsdll32.lib", GhostscriptLicense.GPL);

            using (var _rasterizer = new GhostscriptRasterizer())
            {
                

                //MemoryStream usage sample


                byte[] buffer = File.ReadAllBytes(inputPdfPath);
                MemoryStream ms = new MemoryStream(buffer);
   


                _rasterizer.Open(inputPdfPath, _lastInstalledVersion, true);

                for (int pageNumber = 1; pageNumber <= _rasterizer.PageCount; pageNumber++)
                {
                    string pageFilePath = Path.Combine(outputPath, "Page-" + pageNumber.ToString() + ".png");

                    Image img = _rasterizer.GetPage(desired_x_dpi, desired_y_dpi, pageNumber);
                    img.Save(pageFilePath, ImageFormat.Png);

                    Console.WriteLine(pageFilePath);
                }
            }

@bkwdesign
Copy link

@Amonra69 - I finally figured out that I need to roll back to GS 9.26 before the .NET wrapper works correctly

@Amonra69
Copy link

@Amonra69 - I finally figured out that I need to roll back to GS 9.26 before the .NET wrapper works correctly

you save my time
thank you

@brothers-morrison
Copy link

brothers-morrison commented Jul 5, 2022

note:
this did NOT fix it for me
@Amonra69 - (https://stackoverflow.com/a/56230513/1520850) [you] need to roll back to GS 9.26 before the .NET wrapper works correctly

Trying to use Ghostscript.NET out of the box with the following
switches: -sDEVICE=mswinpr2 -dNoCancel=true -dQueryUser=3 -dPrinted -dBATCH -dNOPAUSE -dNOPROMPT -dNOSAFER -dNumCopies=1 -sOutputFile="%printer%\\network_installed\printer1" "\\network_fileshare\LS-F123.pdf"

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

10 participants