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

Throw "Invalid calling convention 63" Exception when converting PDF file on ubuntu #44

Closed thlinhit closed 8 years ago

thlinhit commented 8 years ago

i got the exception when running this code on Ubuntu, but it works well on Windows and Macos.

` ``` public static void main(String[] args) {
//get Ghostscript instance Ghostscript gs = Ghostscript.getInstance(); //prepare Ghostscript interpreter parameters //refer to Ghostscript documentation for parameter usage String[] gsArgs = new String[10]; gsArgs[0] = "-ps2pdf"; gsArgs[1] = "-dNOPAUSE"; gsArgs[2] = "-dBATCH"; gsArgs[3] = "-dSAFER"; gsArgs[4] = "-sDEVICE=pdfwrite"; gsArgs[5] = "-sOutputFile=output.pdf"; gsArgs[6] = "-c"; gsArgs[7] = ".setpdfwrite"; gsArgs[8] = "-f"; gsArgs[9] = "scansmpl.pdf";

        //execute and exit interpreter
        try {    
            gs.initialize(gsArgs);
            gs.exit();
            System.out.println("Success");   
        } catch (GhostscriptException e) {           
            e.printStackTrace();
        }        
     }`

It throws an exeption as following:

> Exception in thread "main" java.lang.IllegalArgumentException: Invalid calling convention 63
>         at com.sun.jna.Native.createNativeCallback(Native Method)
>         at com.sun.jna.CallbackReference.<init>(CallbackReference.java:239)
>         at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:413)
>         at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:395)
>         at com.sun.jna.Function.convertArgument(Function.java:541)
>         at com.sun.jna.Function.invoke(Function.java:305)
>         at com.sun.jna.Library$Handler.invoke(Library.java:236)
>         at com.sun.proxy.$Proxy0.gsapi_set_stdio(Unknown Source)
>         at org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)
>         at axonteam.explosion.PDFConvert.main(PDFConvert.java:42)

My system:
* Ubuntu14.04 64bit
* JVM 1.7.0_79 64 bit
*  Ghostscript 9.10

Thanks,
Regards,
zippy1978 commented 8 years ago

Hi,

Could you tell me which version of Ghost4J was used ? If it is 1.0.0 : could you try building from master branch (1.0.1-SNAPSHOT) and test again ?

zippy1978 commented 8 years ago

Hi, I just released version 1.0.1 with a JNA library upgrade. Could you try with this release ?

thlinhit commented 8 years ago

Hi, Thanks for your support. I have found a root cause of this issue and it is not related to Ghost4j but another library.

Thanks again,

ghost commented 8 years ago

Hi, I'm having exactly the same problem. Could you say which library was causing the issue / how you solved it? Thanks

4F2E4A2E commented 8 years ago

Are you having the exact same problem with the same OS and GS version with the newer ghost4j version? Are you sure? See https://github.com/zippy1978/ghost4j/releases/tag/1.0.1

ghost commented 8 years ago

I'm using Tess4J and it was the ghost4J module within that which was throwing the exception while converting a PDF to an image for OCR, but it turned out not to be ghost4J that was the problem.

The issue seems to be that Tess4J comes bundled with ghost4j 1.0.1 and JNA 4.2.2. If I switch out JNA 4.2.2 for JNA 4.1.0, that seems to fix the "Invalid calling convention" error and allows ghost4j to do the conversion without issue.

For reference I am on CentOS 6.4 and GS 8.70.

4F2E4A2E commented 8 years ago

Which version of tess4j are you using? We just released a newer version of tess4j using ghost4j 1.0.1 as you said, because we tought to work around this jna problem.

ghost commented 8 years ago

I'm using tess4j 3.1. In the lib folder it's got ghost4j 1.0.1 and jna 4.2.2 - if I build a fat jar for my app with those in there, I get the calling convention issue. If I switch out the jna 4.2.2 for jna 4.1.0 it seems to work.

4F2E4A2E commented 8 years ago

This JNA issue is really boring. Nothing to do here then, thank you anyway, we will investigate and react in the tess4j project since ghost4j uses the 4.1.0 version of jna.