Ghost4j doesn't use the ghostscript installation per se, instead both ghost4j and ghostscript use a library called libgs.so. This library is a dependecy of ghostscript but also comes with an installation called libgs-dev (on Linux).
I am suspecting that somehow Ghost4j uses some leftower version of the library.
So if you are using the latest version of Ubuntu installing libgs-dev should solve the problem, however all current stable versions of Linux default to the 9.18
We solved this problem by manually building that library and symlinking the version we need to the libgs.so file. You can download the compiled dynamically linked version 9.22 of libgs.so here(personal dropbox link) save it under /usr/lib/x86_64-linux-gnu/libgs.so.9.22 and run
ln -fs /usr/lib/x86_64-linux-gnu/libgs.so.9.22
/usr/lib/x86_64-linux-gnu/libgs.so
and, if one does not trust strangers on the internet like one shouldn't here are the instructions for building it yourself:
(tutorial for building gs),
(gs source code).
To make sure everything else is the same we use Ghost4j 1.0.1 and JNA 4.1.0
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.ghost4j</groupId>
<artifactId>ghost4j</artifactId>
<version>1.0.1</version>
</dependency>
While solving this problem I found this endpoint method to be really usefull:
@RequestMapping(value = "/gs/version", method = GET)
public GhostscriptRevision gsVersion() throws IOException {
return Ghostscript.getRevision();
}
Good luck.