Reputation: 181
I'm trying to use the Ghost4j wrapper to convert .ps files to .pdf on macOS 10.12.6 (Sierra)
I have used the sample program found here: http://www.ghost4j.org/highlevelapisamples.html
I have included the all the ghost4j jars and add the ghostscript libraries on the build path.
But I am getting the following error:
org.ghost4j.converter.ConverterException: org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -100
at org.ghost4j.converter.PDFConverter.run(PDFConverter.java:251)
at org.ghost4j.converter.AbstractRemoteConverter.convert(AbstractRemoteConverter.java:85)
at Convert.main(Convert.java:25)
Caused by: org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -100
at org.ghost4j.Ghostscript.initialize(Ghostscript.java:365)
at org.ghost4j.converter.PDFConverter.run(PDFConverter.java:231)
... 2 more
Any suggestions?
Upvotes: 1
Views: 1270
Reputation: 544
In my case the "Cannot initialize Ghostscript interpreter. Error code is -100" was because ghostscript used in multithreaded environment.
http://www.ghost4j.org/threadsafetyandmultithreading.html
adding synchronized in addition to gs.deleteInstance(); helped to resolve the problem
Ghostscript gs = Ghostscript.getInstance();
List<String> args = new ArrayList<String>();
args.add("-dBATCH");
args.add("-dNOPAUSE");
args.add("-sOutputFile=" + outFile.getAbsolutePath());
args.add("-sDEVICE=pdfwrite");
args.add("-dEmbedAllFonts=true");
args.add(inFile.getAbsolutePath());
try {
synchronized(gs) {
gs.initialize(args.toArray(new String[args.size()]));
gs.exit();
gs.deleteInstance();
}
} catch (GhostscriptException gx) {
}
Upvotes: 0
Reputation: 29
it may be a little old but here is my solution: you need to delete the instance at the end of conversion
Ghostscript.deleteInstance();
Upvotes: 2
Reputation: 31199
Try running Ghostscript directly from the command line.
Error -100 is a 'fatal error', something went wrong, and we can't tell what. Can be out of memory, file permission problems, or invalid configuration (or trying to use a 32-bit library when a 64-bit version was expected).
I can't help at all with Ghost4J, which is why I suggest trying to reproduce the problem with Ghostscript itself. If you can do that, or you can get the transcript from stderr/stdout then I may be able to help more.
Upvotes: 1