zippy1978 / ghost4j

Java wrapper for Ghostscript C API + PS/PDF document handling API
http://www.ghost4j.org
GNU Lesser General Public License v3.0
64 stars 38 forks source link

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

Open mananshah88 opened 6 years ago

mananshah88 commented 6 years ago

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 commented 6 years ago

GS can not be initialize, on production only you say? Everything installed and permissions set?

mananshah88 commented 6 years ago

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 commented 6 years ago

What about the permission of the application you’re running?

mananshah88 commented 6 years ago

It has same access level. 'sudo'

kvadlamani commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

@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)