简体   繁体   中英

Ghost4j not using default ghostscript installation

I'm using Ghost4j to render PDFs, but it throws the following sorts of errors sometimes when trying to render documents that were created by MS Word

[main] ERROR org.ghost4j.Ghostscript  - GPL Ghostscript 9.18: Some glyphs of the font TimesNewRoman requires a patented True Type interpreter.

According to this thread this may be due to the Ubuntu Ghostscript package leaving out certain fonts. So I compiled the latest Ghostscript (9.22) from source and installed it, and it's now the version that comes up when I use the gs command, but Ghost4j still seems to be using the old 9.18 version.

How can I tell it to use the new version of Ghostscript?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM