2

I'm trying to convert a ps file (word file with image) to pdf using Ghostscript.

Everything works fine when I'm debugging my code and just stepping thru it, It generates the pdf with the text,images and whatnot. But when I deploy the app using Visual Studio Setup Project, It does not work and gives me this error "An error occured when call to 'gsapi_new_instance' is made: -100."

Here's my command line arguments

var args = string.Format("-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=\"{1}\" -c save pop -f \"{0}\"", inputFile, @"C:\MedirefPrinter\converted\out.pdf");

Any idea why this isn't working? Thanks

Actual Code :

File Changed Handler

ShellCommand

Please excuse my noobness :)

  • Where are you deploying this to? Does the machine have ghostscript installed? – Crowcoder Jul 29 '16 at 12:45
  • Windows workstation. Yup, I installed 32 and 64 bit ghostscript. – Hans Maligro Jul 29 '16 at 12:58
  • It would help to see the actual command line, rather than just the arguments. Are you using 32 or 64 bit Ghostscript ? How are you calling the Ghostscript executable ? If you are using C# or something similar then you aren't using Ghostscript. Possibly you are using Ghostscript.NET. In which case, you should probably be aware of the licencing. Ghostscript is licenced under the AGPL and if you are planning on 'deploying' software which uses it, you'll need to make sure you are compliant with the terms of that licence. – KenS Jul 29 '16 at 13:39
  • Hi @KenS, yes I'm aware of the licensing. We're just doing a test on the product before we actually "purchase" it. But I think that's not the point. Point is, Postscripts with images are only interpreted properyl during debug mode. And when I mentioned 'deployed',I just created an installer with the sample app that I did and tested it. And also, I did try using both 32 and 64 bit of Ghostscript. – Hans Maligro Aug 01 '16 at 02:01
  • Updated the original post and attached some images. – Hans Maligro Aug 01 '16 at 02:12

1 Answers1

0

Moved to an answer to allow more text.

There are three possible reasons for the error:

1) The 'instance' pointer is NULL. I can't see how this is ever possible with our executable as its a globally defined variable and the executable passes its address. This is a sanity check for people writing code against the Ghostscript API.

2) The application was unable to allocate sufficient memory for some internal structures. Again this seems unlikely as your system would have to be unreasonably short on memory.

3) The DLL instance count is already 1 or greater. This can happen if the DLL is shared between multiple processes. Unless you build the library with GS_THREADSAFE it isn't thread safe, and so you can't have multiple processes using the same instance of the DLL. I'd guess that this is your problem but obviously you haven't supplied a full set of code, so I don't know. If you are trying to run more than one copy of Ghostscript simultaneously, from the same directory, then you will get this error.

error -100 means 'something really bad happened so early on that I can't even tell you what it is'.

I very much doubt that the presence of images in the PostScript has any real impact, except that possibly it may slow the interpretation down enough to cause you to attempt to launch two processes.

KenS
  • 30,202
  • 3
  • 34
  • 51