Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Getting org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -13 #62

Open
mananshah88 opened this issue Dec 20, 2017 · 7 comments

Comments

@mananshah88
Copy link

Hi,
I am facing a weird problem. My code works on my machine but not on production. :D :D :D

Ghostscript: 9.18 (2015-10-05)
Ghostscript4j : 1.0.1
jna: 4.1.0
( all versions are same on local machine as well as on production.)

I am trying to create thumbnail from the PDF file.

Here is my code:

Ghostscript gs = Ghostscript.getInstance();
String[] gsArgs = new String[11];
gsArgs[1] = "-sDEVICE=png16m";
gsArgs[2] = "-dPDFFitPage=true";
gsArgs[3] = "-dDEVICEWIDTHPOINTS=680";
gsArgs[4] = "-dDEVICEHEIGHTPOINTS=480";
gsArgs[5] = "-dBATCH";
gsArgs[6] = "-dNOPAUSE";
gsArgs[7] = "-dNOPROMPT";
gsArgs[8] = "-dQUIET";
gsArgs[9] = "-sOutputFile=some_file_name";
gsArgs[10] = "some_input_file_name";

try {
	gs.initialize(gsArgs);
	gs.exit();
} catch (GhostscriptException e) {
	e.printStackTrace();
}

The error I got on my production is:

org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -13
	at org.ghost4j.Ghostscript.initialize(Ghostscript.java:365)
        .....
org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -13

Can anyone gives me any direction?

@4F2E4A2E
Copy link
Collaborator

4F2E4A2E commented Dec 20, 2017 via email

@mananshah88
Copy link
Author

mananshah88 commented Dec 20, 2017

Thanks 4F2E4A2E, for the quick response.
Yup... it seems everything installed perfect with proper permission.


Update:

By enabling debug mode, I can found following errors from my code...

0 [main] **INFO** org.ghost4j.Ghostscript  - **Error**: /rangecheck in --setpagedevice--
1 [main] INFO org.ghost4j.Ghostscript  - Operand stack:
1 [main] INFO org.ghost4j.Ghostscript  -    false   --dict:1/1(L)--   --nostringval--   --dict:85/162(ro)(L)--   --dict:1/1(L)--   --dict:8/86(L)--   --dict:0/0(L)--   --nostringval--   --dict:3/3(L)--   true   --nostringval--   %MediaDestination   0   DisablePageHandler   true   %MediaSource   0   --dict:8/86(L)--   --nostringval--   --nostringval--   0   --nostringval--   false   --nostringval--
1 [main] INFO org.ghost4j.Ghostscript  - Execution stack:
2 [main] INFO org.ghost4j.Ghostscript  -    %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1977   1   3   %oparray_pop   1976   1   3   %oparray_pop   1960   1   3   %oparray_pop   --nostringval--   --nostringval--   1945   1   7   %oparray_pop   --nostringval--   --nostringval--   --nostringval--
2 [main] INFO org.ghost4j.Ghostscript  - Dictionary stack:
2 [main] INFO org.ghost4j.Ghostscript  -    --dict:1196/1684(ro)(G)--   --dict:1/20(G)--   --dict:83/200(L)--   --dict:83/200(L)--   --dict:132/256(ro)(G)--   --dict:283/300(ro)(G)--   --dict:26/32(L)--
2 [main] **INFO** org.ghost4j.Ghostscript  - **Current allocation mode is local**
2 [main] **INFO** org.ghost4j.Ghostscript  - **Last OS error: No such file or directory**
2 [main] **ERROR** org.ghost4j.Ghostscript  - **GPL Ghostscript 9.18: Unrecoverable error, exit code 1**

Exception generated during pdf thumbnail processing.
org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -100
	at org.ghost4j.Ghostscript.initialize(Ghostscript.java:365)
        ....

(OS: ubuntu 16)

Any ideas??
Do I need to set any PATH or any environment variable?

Thanks in advance.

@4F2E4A2E
Copy link
Collaborator

4F2E4A2E commented Dec 20, 2017 via email

@mananshah88
Copy link
Author

It has same access level. 'sudo'

@kvadlamani
Copy link

@mananshah88 Could you please let us know how you've enabled debug mode in Ghost4j? I am getting the same exception "Cannot initialize Ghostscript interpreter". But the Error code is -15 instead of -100. I am setting parameters for debugging but it doesn't seem to work. Thanks in advance.

@mananshah88
Copy link
Author

@kvadlamani sorry its a very old thread. So i do not remember exactly.
But there are parameters like "-dPDFDEBUG, -dPDFWRDEBUG" which could help you.

There are others as well. You can get it from here: https://www.ghostscript.com/doc/current/Use.htm#Environment_variables (13. Debugging section)

@kvadlamani
Copy link

kvadlamani commented Jul 12, 2019

@mananshah88 Thanks for the reply. Unfortunately, none of the debug options worked for me. This is the code I am trying to execute:

public static void main(String[] args) throws GhostscriptException {
	final Ghostscript gs = Ghostscript.getInstance();
	final String basePath = "/usr/local/downloads/";
	final String fileName = "xyz";
	final String[] gsArgs = getArgs(basePath, fileName);
	gs.initialize(gsArgs);
}

private static String[] getArgs(String basePath, String fileName) {
	final ArrayList<String> args = new ArrayList<String>();
	args.add("-sDEVICE=pdfwrite");
	args.add("-dPDFX");
	args.add("-dBATCH");
	args.add("-dNOPAUSE");
	args.add("-dNOOUTERSAVE");
	args.add("-sProcessColorModel=DeviceCMYK");
	args.add("-dUsePDFX3Profile");
	args.add("-sOutputFile=" + basePath + fileName + "-x1a.pdf");
	args.add(basePath + "PDFX1A_def.ps");
	args.add(basePath + fileName + ".pdf");
	return args.toArray(new String[0]);
} 

and I am getting the exception:

Exception in thread "main" org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -15
	at org.ghost4j.Ghostscript.initialize(Ghostscript.java:365)
	at com.testing.DisplayCallbackExample.main(DisplayCallbackExample.java:24)

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

No branches or pull requests

3 participants