4

我正在尝试使用 Ghost4J 将 PDF 转换为 PNG。我知道以前有人问过这个问题,但在 OS X 10 和最新版本的 Ghost4J 中没有。

我已按照此处的 zippy1978 答案中列出的说明进行操作:PDF to image using Java

我已经关注了Ghost4J 页面上的所有内容

我也从这里尝试了两个答案:我如何在 OS X 10.9 上使用 ghost4j

我已经用Port安装了 Ghostscript,并从Richard Koch 的网站上进行了尝试。

我继续收到此错误:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.UnsatisfiedLinkError: Unable to load library 'gs': dlopen(libgs.dylib, 9): image not found] with root cause

java.lang.UnsatisfiedLinkError: Unable to load library 'gs': dlopen(libgs.dylib, 9): image not found
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
    at com.sun.jna.Library$Handler.<init>(Library.java:140)
    at com.sun.jna.Native.loadLibrary(Native.java:393)
    at com.sun.jna.Native.loadLibrary(Native.java:378)
    at org.ghost4j.GhostscriptLibraryLoader.loadLibrary(GhostscriptLibraryLoader.java:39)
    at org.ghost4j.GhostscriptLibrary.<clinit>(GhostscriptLibrary.java:34)
    at org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)
    at org.ghost4j.renderer.SimpleRenderer.run(SimpleRenderer.java:105)
    at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:86)
    at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:70)
    at com.xxxx.yyyy.controller.rest.yyyyyController.zzzz(yyyyyController.java:182)

我在这里想念什么?

我的控制器中崩溃的代码是这样的(我标记了该行):

// imgSrc is the PDF in Base 64 and output file is a File

byte[] imageByte;
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imgSrc);
outputfile = new File("image.pdf");
OutputStream fop = new FileOutputStream(outputfile);
fop.write(imageByte);
fop.flush();
fop.close();
PDFDocument document = new PDFDocument();
document.load(outputfile);
SimpleRenderer renderer = new SimpleRenderer();
renderer.setResolution(300);
List images = renderer.render(document);       //CRASH TAKES PLACE HERE ***
outputfile = new File("image.png");
ImageIO.write((RenderedImage) images.get(0), "png", outputfile);
4

1 回答 1

1

所以我想通了!

我在这次谈话中找到了答案:

我有同样的问题,虽然我已经安装了 macports 包“ghostscript”。设置 LD_LIBRARY_PATH 有助于:

$ export LD_LIBRARY_PATH=/opt/local/lib

这导致了一条警告消息:

log4j:WARN No appenders could be found for logger (slideselector.facedata.FaceDataParser).
log4j:WARN Please initialize the log4j system properly.

借助以下方法解决了哪个问题:如何正确初始化 log4j?

对于像我这样的所有 maven 人:将 log4j.properties 放入 src/main/resources

于 2015-08-13T20:21:41.930 回答