问题描述
我正在尝试使用Ghost4J将PDF转换为PNG。我知道人们之前已经问过这个问题,但不是OS X 10以及Ghost4J的最新版本。
我已经按照zippy1978的回答中的说明从这里开始了:
我已经关注了
如何我可以在OS X 10.9上使用ghost4j
我已经用并尝试过。
我继续收到此错误:
servlet的Servlet.service() [dispatcherServlet]中的con带有路径[]的文本引发异常[处理程序处理失败;嵌套异常是java.lang.UnsatisfiedLinkError:无法加载库'gs':dlopen(libgs.dylib,9):image not found] with root cause
java.lang.UnsatisfiedLinkError:无法加载library'gs':dlopen(libgs.dylib,9):图片未找到
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)
在org.ghost4j.GhostscriptLibrary。< clinit>(GhostscriptLibrary.java:34)
at org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)
at org.ghost4j.renderer.SimpleRenderer。在org.ghost4j.renderer.AbstractRemoteRenderer.render上运行(SimpleRenderer.java:105)
(AbstractRemot eRenderer.java:86)
at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:70)
at com.xxxx.yyyy.controller.rest.yyyyyController.zzzz(yyyyyController.java: 182)
我在这里缺少什么?
我的控制器崩溃的代码是这个(我标记了行):
// imgSrc是PDF in Base 64和输出文件是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);
所以我已经弄明白了!
我在中找到了答案:
这会引发一条警告消息:
log4j:WARN找不到记录器(slideselector.facedata.FaceDataParser)的appender。
log4j:WARN请正确初始化log4j系统。
这是通过以下方式解决的:
I am trying to use Ghost4J in order to turn a PDF into a PNG. I am aware that people have asked this before, but not with OS X 10 and with the latest release of Ghost4J.
I have followed the instructions listed in zippy1978's answer from here: PDF to image using Java
I have followed everything from the Ghost4J page
I also have tried both answers from here: How can i use ghost4j on OS X 10.9
And I have installed Ghostscript with Port and have tried from Richard Koch's website.
I continue to get this error:
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)
What am I missing here?
The code from my Controller that is crashing is this (I marked the line):
// 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);
So I have figured it out!
I found the answer in this conversation:
This caused a warning message:
log4j:WARN No appenders could be found for logger (slideselector.facedata.FaceDataParser).
log4j:WARN Please initialize the log4j system properly.
Which was solved by the help of: How to initialize log4j properly?
这篇关于无法使用Ghost4J加载库'gs'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!