You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "S. Woodside" <sb...@yahoo.com> on 2008/02/26 07:19:36 UTC
running batik efficiently in a web server environment (linux)
Hi there,
I'm developing a workflow where I have an SVG file, I modify some of
the elements (sort of like variable printing) and then I want my
users to be able to download the result as SVG, or as PDF. I'm
thinking of using batik for the PDF "rasterizing", it does a really
good job in my tests and it runs well on my debian box (nice job!)
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.
What's the best/easiest way to do this? Should I set up a java-based
server and do some kind of RPC on it (like REST calls on localhost),
or can I run batik as a daemon or something?
--simon
PS I don't have any experience running any java servers (yet)
--
http://simonwoodside.com
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: running batik efficiently in a web server environment (linux)
Posted by "S. Woodside" <sb...@yahoo.com>.
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:heycam@jabber.org ▪ ICQ 26955922 ▪ MSN cam@mcc.id.au
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-
> help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: running batik efficiently in a web server environment (linux)
Posted by Cameron McCormack <ca...@mcc.id.au>.
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:heycam@jabber.org ▪ ICQ 26955922 ▪ MSN cam@mcc.id.au
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: running batik efficiently in a web server environment (linux)
Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
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!
On 26.02.2008 07:19:36 S. Woodside wrote:
> Hi there,
>
> I'm developing a workflow where I have an SVG file, I modify some of
> the elements (sort of like variable printing) and then I want my
> users to be able to download the result as SVG, or as PDF. I'm
> thinking of using batik for the PDF "rasterizing", it does a really
> good job in my tests and it runs well on my debian box (nice job!)
>
> 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.
>
> What's the best/easiest way to do this? Should I set up a java-based
> server and do some kind of RPC on it (like REST calls on localhost),
> or can I run batik as a daemon or something?
>
> --simon
>
> PS I don't have any experience running any java servers (yet)
>
> --
> http://simonwoodside.com
>
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org