5

我正在运行以下代码以使用 Ghost4j 从 pdf 创建 bmp 图像

我有一个由 GhostScript 生成器执行的命令,用于从 pdf 生成页面的 Bmp 图像。代码是:

package ghost;

import net.sf.ghost4j.Ghostscript;
import net.sf.ghost4j.GhostscriptException;

public class GhostDemo {
public static void main(String[] a){
    Ghostscript gs = Ghostscript.getInstance(); //create gs instance
    String[] gsArgs = new String[10];/*command string array*/
    gsArgs[0] = "-dUseCropBox";/*use crop box*/
    gsArgs[1] = "-dNOPAUSE";
    gsArgs[2] = "-dBATCH";
    gsArgs[3] = "-dSAFER";
    gsArgs[3] = "-r300";
    gsArgs[4] = "-sDEVICE=bmp16m";
    gsArgs[6] = "-dTextAlphaBits=4";
    gsArgs[5] = "-sOutputFile=C:/PagesWorkspace/1/masterData/1.bmp";/*bmp file location with name*/
    gsArgs[6] = "C:/MasterWorkspace/pipeline.pdf";/*pdf location with name*/

    try {

        gs.initialize(gsArgs);  /*initialise ghost interpreter*/
        gs.exit();

    } catch (GhostscriptException e) {
       e.printStackTrace();
    }
}
}

我得到了例外

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gsdll32': The specified module could not be found.

    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188)
    at com.sun.jna.Library$Handler.<init>(Library.java:123)
    at com.sun.jna.Native.loadLibrary(Native.java:255)
    at com.sun.jna.Native.loadLibrary(Native.java:241)
    at net.sf.ghost4j.GhostscriptLibraryLoader.loadLibrary(GhostscriptLibraryLoader.java:36)
    at net.sf.ghost4j.GhostscriptLibrary.<clinit>(GhostscriptLibrary.java:32)
    at net.sf.ghost4j.Ghostscript.initialize(Ghostscript.java:292)
    at ghost.GhostDemo.main(GhostDemo.java:22)

谁能告诉我为什么我会得到这个例外?

4

3 回答 3

13

你有安装 Ghostscript 吗?

  • 如果是,是哪个版本?
  • 如果是,在哪个位置?
  • 它包括一个文件gsdll32.dll吗?

如果没有,请下载适用于 Win32 的 Ghostscript 安装程序并运行它。gsdll32.dll安装后,目录下应该有一个文件%your_install_dir%\gs\gs9.05\bin\

于 2012-06-22T20:23:05.977 回答
6

在eclipse项目中粘贴dll文件使我的程序工作!

于 2013-01-11T11:12:06.583 回答
2

对于 SO 社区,要检查此错误的另一件事是您使用的是 32 位 Java。如果您的 Java 实例是 64 位,您将收到完全相同的消息:

Unable to load library 'gsdll32': The specified module could not be found.

即使您指向正确的 dll,也无需任何进一步解释。

于 2013-05-22T22:17:27.443 回答