zippy1978 / ghost4j

Java wrapper for Ghostscript C API + PS/PDF document handling API
http://www.ghost4j.org
GNU Lesser General Public License v3.0
64 stars 38 forks source link

PSConverter does not work in Servlet #31

Closed MFEKN closed 10 years ago

MFEKN commented 10 years ago

I want to use Ghost4J to convert PDF to PS. Locally it works fine but i want to use it in a servlet running on Glassfish.

I use following Code (returns the postscript zipped)

ByteArrayInputStream bais = new ByteArrayInputStream(data);
PDFDocument doc = new PDFDocument();
doc.load(bais);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
ZipEntry entry = new ZipEntry(PS_OUT);
zos.putNextEntry(entry);

PSConverter converter = new PSConverter();
converter.setPaperSize(PaperSize.A4);
//converter.setMaxProcessCount(5);
converter.convert(doc, zos);

baos.close();
bais.close();
zos.closeEntry();
zos.close();

return baos.toByteArray();

If i dont use "setMaxProcess" then i get following error: org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -21

If i use it i get java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:java.io.EOFException

Does anybody know what is missing?

PS: Actually Glassfish Server crashes when i call above coding!

zippy1978 commented 10 years ago

Hi, What do you mean by 'locally' ? Is Glassfish running on the same machine as your working code ? What is the Ghostscript version ? Ghostscript initialization error is often due to a missing resource or unknown parameter when calling Ghostscript...

Regards,

MFEKN commented 10 years ago

Yes, code runs in an executeable JAR-File on the same machine! We will try to put needed libraries of Ghost4J directly on the Glassfish-Server, will report if it works then

MFEKN commented 10 years ago

After putting all libs to :/oracle/v01/product/glassfish4/glassfish/domains/domain1/lib

it works!

But just found out if servlet is called more times in a row "Fehler beim PDF2PS: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: java.io.EOFException"

still occurs!

MFEKN commented 10 years ago

Have now implemented a Singleton Class for using the PSConverter. So it is only once available in the Servlet! Now it seems that it runs!