【问题标题】:PS to PDF conversion. GhostScript Exception - Cannot initialize Ghostscript interpreter. Error code is -100PS转PDF。 GhostScript 异常 - 无法初始化 Ghostscript 解释器。错误代码是-100
【发布时间】:2019-04-02 20:20:38
【问题描述】:

我正在 Linux 服务器中为我的应用程序运行 PostScript 到 PDF 的转换服务。我安装了 ghostscript 8.70 版。我在 Windows 中使用 gsdll64.dll、ghostscript 9.26 测试代码,它运行良好。 我在我的 pom 文件中添加了 jna 4.1.0 和 ghost4j 1.0.1 依赖项。

当我运行程序时,出现以下错误:

Caused by: org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -100
    at org.ghost4j.Ghostscript.initialize(Ghostscript.java:365)
    at org.ghost4j.converter.PDFConverter.run(PDFConverter.java:231)

我的代码如下所示:

    InputStream iis = null;
    ByteArrayOutputStream bos = null;
    try {
        //load the bytes data into the inputstream
        iis = new ByteArrayInputStream(psBytes);
        //create the byte array output stream
        bos = new ByteArrayOutputStream();

        //load PostScript bytes through input stream
        PSDocument document = new PSDocument();
        document.load(iis);

        //create converter
        PDFConverter converter = new PDFConverter();
        //set options
        converter.setPDFSettings(PDFConverter.OPTION_PDFSETTINGS_PREPRESS);
        converter.convert(document, bos);
        return bos.toByteArray();
    }catch (org.ghost4j.document.DocumentException de){
        String[] errArg = {de.getMessage()};
        throw new ApplicationException(ErrorCode.XXXXX, errArg);
    }

【问题讨论】:

    标签: java ghostscript ghost4j


    【解决方案1】:

    所以,您使用的不是 Ghostscript,而是 Ghost4j。您的第一步应该是从命令行初始化 Ghostscript 本身;只需执行“gs”,看看会发生什么。

    错误 -100 只是意味着“发生了致命的事情”,我对 Ghost4j 不熟悉,但大概有一些方法可以查看 stdout 和 stderr 上发生了什么,在这些通道上发回了哪些消息?

    【讨论】:

      【解决方案2】:

      我可以通过升级 Ghostscript 的版本来解决它。当我安装 9 以上版本的 Ghostscript 时,它可以工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-23
        • 1970-01-01
        • 1970-01-01
        • 2018-11-10
        • 2016-07-13
        • 2016-04-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多