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 Shayer Huda <sh...@gmail.com> on 2005/05/17 08:39:31 UTC

Error converting svg to PDF

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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Error converting svg to PDF

Posted by Shayer Huda <sh...@gmail.com>.
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 <Th...@kodak.com> 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: 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
> 
>

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


Re: Error converting svg to PDF

Posted by Thomas DeWeese <Th...@Kodak.com>.
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: 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