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 Jan Tosovsky <j....@tiscali.cz> on 2012/02/20 22:25:04 UTC

PDF transcoder performance

Dear All,

in my project I need to convert 2 svg files into a single PDF file.

1) The first approach was to wrap SVG files by FO code and generate the PDF
output via Apache FOP. It works fine, but recently I've found that FOP is
somehow leaking and does not release objects properly so this solution ends
very quickly with heap space memory errors.

2) The second approach was to use Batik's PDF transcoder to produce two
separate single page PDF files and merge them using the Apache PDFBox
library.

Unfortunately, this solution is very slow, especially the Transcoder's
transcode method:

private static byte[] getPDFByteArray(InputStream svgStream) throws
Exception {
   Transcoder t = new PDFTranscoder();
   TranscoderInput input = new TranscoderInput(svgStream);

   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   BufferedOutputStream outputBuff = new BufferedOutputStream(outputStream);
   TranscoderOutput output = new TranscoderOutput(outputBuff);
   t.transcode(input, output);

   return outputStream.toByteArray();
}

While the first approach needs approx 2 seconds to complete the task (SVG
files are quite complex), the second solution takes approx 8 seconds on my
computer (transcode method itself 7 seconds).

Does anybody have any hint how to improve the performance of my code? Are
there any secret speed up switches?

Thanks,

Jan


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: PDF transcoder performance

Posted by Johan Stuyts <j....@javathinker.com>.
>    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
>    BufferedOutputStream outputBuff = new  
> BufferedOutputStream(outputStream);

There is no performance gain in buffering an in-memory output stream. You  
will likely see a tiny decrease in performance instead.

I am pretty sure that you won't notice any difference, but what you can  
try is to start with a bigger buffer size (e.g. 1 MB) to prevent some  
copying of the data as it grows:
<http://docs.oracle.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html#ByteArrayOutputStream(int)>

Regards,

Johan

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: PDF transcoder performance

Posted by amey <am...@citiustech.com>.
Hi Jane,
Can you tell me how you are able to generate single pdf using two or more
svgs?



--
View this message in context: http://batik.2283329.n4.nabble.com/PDF-transcoder-performance-tp4405171p4655264.html
Sent from the Batik - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org