Error converting svg to PDF

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Error converting svg to PDF

Shayer Huda
Hello

I am trying to convert a svg file to PDF using BATIK and FOP. I write
the following code ... It works fine for small svg files. But when i
open a relatively large SVG file and try to convert that into PDF it
gives me the following error

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError:
Java heap space

We can allocate more memory to Java Runtime but i dont think that
would be a good solution.

Can anybody please tell me how can i optimize the memory usage to
convert the svg to pdf. Is there anyother way around to do this ???

Shayer

Code :
=========================================================


public void svg2pdf(File svg, File pdf) throws IOException,
TranscoderException {
       
        //Create transcoder
        Transcoder transcoder = new PDFTranscoder();
        //Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();
       
        //Setup input
        InputStream in = new java.io.FileInputStream(svg);
        try {
            TranscoderInput input = new TranscoderInput(in);
           
            //Setup output
            OutputStream out = new java.io.FileOutputStream(pdf);
            out = new java.io.BufferedOutputStream(out);
            try {
                TranscoderOutput output = new TranscoderOutput(out);
               
                //Do the transformation
                transcoder.transcode(input, output);
            } finally {
                out.close();
            }
        } finally {
            in.close();
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Error converting svg to PDF

thomas.deweese
Hi Shayer,

Shayer Huda wrote:

> I am trying to convert a svg file to PDF using BATIK and FOP. I write
> the following code ... It works fine for small svg files. But when i
> open a relatively large SVG file and try to convert that into PDF it
> gives me the following error
>
> Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError:
> Java heap space
>
> We can allocate more memory to Java Runtime but i dont think that
> would be a good solution.

    It looks like you need to allocate more memory.  The default
partition is pretty small by todays standards (64MB).

> Can anybody please tell me how can i optimize the memory usage to
> convert the svg to pdf. Is there anyother way around to do this ???

    My guess is that either you have a large for SVG document or
it is having to rasterize lots of elements (rasterization is neeeded
for features like fiters and some types of opacity).

> =========================================================
>
>
> public void svg2pdf(File svg, File pdf) throws IOException,
> TranscoderException {
>        
>         //Create transcoder
>         Transcoder transcoder = new PDFTranscoder();
>         //Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();
>        
>         //Setup input
>         InputStream in = new java.io.FileInputStream(svg);
>         try {
>             TranscoderInput input = new TranscoderInput(in);
>            
>             //Setup output
>             OutputStream out = new java.io.FileOutputStream(pdf);
>             out = new java.io.BufferedOutputStream(out);
>             try {
>                 TranscoderOutput output = new TranscoderOutput(out);
>                
>                 //Do the transformation
>                 transcoder.transcode(input, output);
>             } finally {
>                 out.close();
>             }
>         } finally {
>             in.close();
>         }
>     }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Error converting svg to PDF

Shayer Huda
Hello

Thanks for your reply.

Yeah java has a very little memory space. But as i am trying to
develop a web application it wont be a good solution to allocate more
memory. Becasue some user may not have that much memory at their end.

Can you please give me some solution how can i do the rasterization ?
I have tried to convert the svg to ps format. It works fine. But the
only problem is it losses its quality.

How can i do rasterization in converting svg to pdf?

regards

On 5/18/05, Thomas DeWeese <[hidden email]> wrote:

> Hi Shayer,
>
> Shayer Huda wrote:
>
> > I am trying to convert a svg file to PDF using BATIK and FOP. I write
> > the following code ... It works fine for small svg files. But when i
> > open a relatively large SVG file and try to convert that into PDF it
> > gives me the following error
> >
> > Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError:
> > Java heap space
> >
> > We can allocate more memory to Java Runtime but i dont think that
> > would be a good solution.
>
>    It looks like you need to allocate more memory.  The default
> partition is pretty small by todays standards (64MB).
>
> > Can anybody please tell me how can i optimize the memory usage to
> > convert the svg to pdf. Is there anyother way around to do this ???
>
>    My guess is that either you have a large for SVG document or
> it is having to rasterize lots of elements (rasterization is neeeded
> for features like fiters and some types of opacity).
>
> > =========================================================
> >
> >
> > public void svg2pdf(File svg, File pdf) throws IOException,
> > TranscoderException {
> >
> >         //Create transcoder
> >         Transcoder transcoder = new PDFTranscoder();
> >         //Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();
> >
> >         //Setup input
> >         InputStream in = new java.io.FileInputStream(svg);
> >         try {
> >             TranscoderInput input = new TranscoderInput(in);
> >
> >             //Setup output
> >             OutputStream out = new java.io.FileOutputStream(pdf);
> >             out = new java.io.BufferedOutputStream(out);
> >             try {
> >                 TranscoderOutput output = new TranscoderOutput(out);
> >
> >                 //Do the transformation
> >                 transcoder.transcode(input, output);
> >             } finally {
> >                 out.close();
> >             }
> >         } finally {
> >             in.close();
> >         }
> >     }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]