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

我从这里按照zippy1978的答案中列出的说明进行操作:PDF to image using Java

我已经遵循了Ghost4J page中的所有内容

我也从这里尝试过两个答案:How can i use ghost4j on OS X 10.9

我已经用Port安装了Ghostscript并尝试了Richard Koch's website

我继续收到此错误:

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);

最佳答案

所以我想通了!
我在conversation中找到了答案:

尽管安装了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.
通过以下帮助解决了该问题:How to initialize log4j properly?

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

10-07 22:57