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:
I had the same problem, although I had installed macports package "ghostscript" already. Setting LD_LIBRARY_PATH helped:
$ export LD_LIBRARY_PATH=/opt/local/lib
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?
For all maven guys like me: put the log4j.properties into src/main/resources
来源:https://stackoverflow.com/questions/31996746/unable-to-load-library-gs-with-ghost4j