On Mar 5, 2008, at 10:17 PM, Cameron McCormack wrote:
As Jeremias says, something that keeps a JVM running all the time is
what you need.  I wrote a small, sample transcoding Java servlet here:

  http://mcc.id.au/2007/09/batik-course/code/transcoding-servlet/

Thank you so much for this. I took your servlet and modified it a bit, running it under Jetty, to make it output PDF. See the new code below.

I had a bit of a problem with your servlet, with jetty 5 not being happy with xerces. Anyway, tossed out your lib directory you had and wound up needing only these ones:

avalon-framework-4.2.0.jar
batik-all-1.6.jar
commons-io-1.3.1.jar
fop.jar
xmlgraphics-commons-1.2.jar

--simon

PS It's very quick :-)



// Source for TranscodingServlet.java
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.fop.svg.PDFTranscoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

public class TranscodingServlet extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException {
        response.setContentType("application/pdf");
        String uri = request.getParameter("uri");
        PDFTranscoder t = new PDFTranscoder();
        TranscoderInput input = new TranscoderInput(uri);
TranscoderOutput output = new TranscoderOutput (response.getOutputStream());
        try {
            t.transcode(input, output);
        } catch (TranscoderException ex) {
            throw new ServletException(ex);
        }
    }
}

--
http://simonwoodside.com


On Mar 5, 2008, at 10:17 PM, Cameron McCormack wrote:
Hi Simon.

S. Woodside:
The thing is, my web app is in Rails, and I'm not too sure if doing a
system() call out to run batik is going to be very efficient. I seem
to recall that running java -jar has a lot of overhead, and then
maybe there's memory issues, or other things? I know that batik takes
several seconds on my (old) server to render my test SVG to PDF, and
I need sub-second times.

Jeremias Maerki:
You're on the right track. You'd have to write a web service wrapper
around Batik. Or you could put it in a servlet. I don't think there's
anything that you could use out-of-the-box. Good luck!

As Jeremias says, something that keeps a JVM running all the time is
what you need.  I wrote a small, sample transcoding Java servlet here:

  http://mcc.id.au/2007/09/batik-course/code/transcoding-servlet/

You could have that running, and invoke it (via HTTP) from your rails
application.

Jetty is a simple Java servlet container that you can use to run the
above servlet.

--
Cameron McCormack, http://mcc.id.au/
        xmpp:[EMAIL PROTECTED]  ▪  ICQ 26955922  ▪  MSN [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: batik-users- [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to