PS到PDF的转换。 GhostScript异常 - 无法初始化Ghostscript解释器。错误代码是-100

问题描述 投票:1回答:2

我正在为Linux Server中的应用程序运行PostScript到PDF转换服务。我安装了ghostscript版本8.70。我正在使用gsdll64.dll,ghostscript 9.26在Windows中测试代码,它运行正常。我在我的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
2个回答
0
投票

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

错误-100只意味着'发生致命事件',我不熟悉Ghost4j,但可能有一些方法可以看到stdout和stderr上发生了什么,这些频道上发回了什么消息?


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.