我正在使用 Ghost4j 来呈现 PDF,但在尝试呈现由 MS Word 创建的文档时有时会抛出以下类型的错误
[main] ERROR org.ghost4j.Ghostscript - GPL Ghostscript 9.18: Some glyphs of the font TimesNewRoman requires a patented True Type interpreter.
根据 this thread这可能是由于 Ubuntu Ghostscript 包遗漏了某些字体。所以我从源码编译了最新的Ghostscript(9.22)并安装了它,现在是我使用gs
命令时出现的版本,但是Ghost4j似乎仍然使用旧的9.18版本。
如何让它使用新版本的 Ghostscript?
最佳答案
Ghost4j 本身不使用 ghostscript 安装,而是 ghost4j 和 ghostscript 使用一个名为 libgs.so 的库。这个库是 ghostscript 的依赖,但也带有一个名为 libgs-dev 的安装(在 Linux 上)。 我怀疑 Ghost4j 以某种方式使用了该库的某些左版本。 因此,如果您使用的是最新版本的 Ubuntu,安装 libgs-dev 应该可以解决问题,但是所有当前稳定版本的 Linux 默认为 9.18 我们通过手动构建该库并将我们需要的版本符号链接(symbolic link)到 libgs.so 文件来解决这个问题。您可以下载libgs.so编译好的9.22动态链接版本here(personal dropbox link)保存到/usr/lib/x86_64-linux-gnu/libgs.so.9.22下运行
ln -fs /usr/lib/x86_64-linux-gnu/libgs.so.9.22
/usr/lib/x86_64-linux-gnu/libgs.so
而且,如果一个人不信任互联网上的陌生人,那么这里是您自己构建它的说明: (tutorial for building gs) , (gs source code) . 为了确保其他一切都相同,我们使用 Ghost4j 1.0.1 和 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>
在解决这个问题时,我发现这个端点方法非常有用:
@RequestMapping(value = "/gs/version", method = GET)
public GhostscriptRevision gsVersion() throws IOException {
return Ghostscript.getRevision();
}
祝你好运。
关于java - Ghost4j 不使用默认的 ghostscript 安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46947105/