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 Arian Hojat <ar...@gmail.com> on 2005/05/02 12:45:36 UTC

saving svg as jpeg on tomcat server

whoops i might have sent this email be4 prematurely.... rewriting just
to make sure.....

Hello all,
I have a function to save my svg document as a jpeg. i fixed my code
from be4 so unix or windows filepaths shouldnt make a difference. it
works fine in windows. but on unix, it saves a 0 kb jpg and throws an
exception somewhere as my code does not go completely through and get
the standard 'The page cannot be displayed' page.
I was wondering am i doing something screwy here?



 public static void saveJPEG(Document svgDoc, String fullPath,
PrintWriter out) {
        //printwriter used for debugging in servlet
        JPEGTranscoder t = new JPEGTranscoder();

        FileInputStream blah = null;
        TranscoderInput input = null;
        FileOutputStream ostream = null;
        TranscoderOutput output = null;
        
        File f = null;
        
        input = new TranscoderInput( svgDoc );
        
        f = new File(fullPath+     "yyyy.jpg");

        
        try {
            ostream = new FileOutputStream(f);
        } catch(FileNotFoundException e) {
            e.getMessage();
        }
        output = new TranscoderOutput(ostream);

        try {
>stack trace says there is a problem here....           
t.transcode(input, output);
        } catch( TranscoderException e) {
            e.getMessage();
        }
        
        try{
            ostream.flush();
            ostream.close();
        } catch(IOException e) {
            e.getMessage();
        }
        
        
    }


here is a stack trace on tomcat if anyone wants a look:

java.lang.NoClassDefFoundError
	java.lang.Class.forName0(Native Method)
	java.lang.Class.forName(Class.java:141)
	java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
	java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
	org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)
	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.copyData(Unknown Source)
	org.apache.batik.ext.awt.image.rendered.TileCacheRed.genRect(Unknown Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.drawBlockInPlace(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.drawBlock(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.copyToRasterByBlocks(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.AbstractTiledRed.copyData(Unknown
Source)
	org.apache.batik.ext.awt.image.rendered.TranslateRed.copyData(Unknown Source)
	org.apache.batik.ext.awt.image.rendered.PadRed.copyData(Unknown Source)
	org.apache.batik.gvt.renderer.StaticRenderer.repaint(Unknown Source)
	org.apache.batik.gvt.renderer.StaticRenderer.repaint(Unknown Source)
	org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
	org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
	org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
	w6.saveJPEG(w6.java:254)
	w6.imageTest(w6.java:413)
	w6.doGet(w6.java:199)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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


Re: saving svg as jpeg on tomcat server

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Arian,

Arian Hojat wrote:

> I guess some imaging/gui type code needs X support off? This is what
> headless means? This seems to be what i found out from googling.

    Yes, normally when the AWT toolkit is booted it contacts the
X Server so it can provide info about the 'graphics environment'
(color depth, fonts etc).  Headless means that there isn't a
display attached.

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


Re: saving svg as jpeg on tomcat server

Posted by Arian Hojat <ar...@gmail.com>.
I took off early from work to come back to college n try it out. i
cannot express the joy and satisfaction of finally getting some Batik
to work with Tomcat! hah.
I am gonna break out some inspirational 70's rock music: "Dont Stop
Beleivin' " heh.

I guess some imaging/gui type code needs X support off? This is what
headless means? This seems to be what i found out from googling.






On 5/2/05, Arian Hojat <ar...@gmail.com> wrote:
> hey thanx for the tip guys. I'll try it tonight... Also I am curious
> what exactly does this headless option for awt have to do with batik?
> Does everyone who uses tomcat and batik do this the 1st time or
> special cases (i just installed the server last month so it hasn't
> seen much action other than batik)?
> 
> thanks,
> Arian
> 
> On 5/2/05, Måns Rullgård <mr...@inprovide.com> wrote:
> > Thomas DeWeese <Th...@Kodak.com> writes:
> >
> > > Hi Arian,
> > >
> > > Arian Hojat wrote:
> > >
> > >> I was wondering am i doing something screwy here?
> > >
> > >     I don't think so, but it looks like the tomcat
> > > JVM might be a little confused/corrupt.  What version
> > > of java is it using?
> > >
> > > Are you running tomcat with '-Djava.awt.headless=true'?
> > >
> > >     Normally you get a can't start AWT message but since
> > > this is the first time AWT is accessed it might be
> > > related.  Or was someone using the headless AWT replacement
> > > at one time?  I think that set a property that was supposed
> > > to replace the Sun Graphics engine.  Perhaps those classes
> > > weren't copied over?
> >
> > I always get that exact error with fresh installs of Sun JDK and
> > Tomcat if -Djava.awt.headless=true is missing.  It took me a few
> > moments to figure it out the first time.
> >
> > >> here is a stack trace on tomcat if anyone wants a look:
> > >> java.lang.NoClassDefFoundError
> > >>      java.lang.Class.forName0(Native Method)
> > >>      java.lang.Class.forName(Class.java:141)
> > >>      java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
> > >>      java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
> > >>      org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
> > >>      org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)
> >
> > --
> > Måns Rullgård
> > mru@inprovide.com
> >
> >
> > ---------------------------------------------------------------------
> > 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: saving svg as jpeg on tomcat server

Posted by Arian Hojat <ar...@gmail.com>.
hey thanx for the tip guys. I'll try it tonight... Also I am curious
what exactly does this headless option for awt have to do with batik?
Does everyone who uses tomcat and batik do this the 1st time or
special cases (i just installed the server last month so it hasn't
seen much action other than batik)?

thanks,
Arian

On 5/2/05, Måns Rullgård <mr...@inprovide.com> wrote:
> Thomas DeWeese <Th...@Kodak.com> writes:
> 
> > Hi Arian,
> >
> > Arian Hojat wrote:
> >
> >> I was wondering am i doing something screwy here?
> >
> >     I don't think so, but it looks like the tomcat
> > JVM might be a little confused/corrupt.  What version
> > of java is it using?
> >
> > Are you running tomcat with '-Djava.awt.headless=true'?
> >
> >     Normally you get a can't start AWT message but since
> > this is the first time AWT is accessed it might be
> > related.  Or was someone using the headless AWT replacement
> > at one time?  I think that set a property that was supposed
> > to replace the Sun Graphics engine.  Perhaps those classes
> > weren't copied over?
> 
> I always get that exact error with fresh installs of Sun JDK and
> Tomcat if -Djava.awt.headless=true is missing.  It took me a few
> moments to figure it out the first time.
> 
> >> here is a stack trace on tomcat if anyone wants a look:
> >> java.lang.NoClassDefFoundError
> >>      java.lang.Class.forName0(Native Method)
> >>      java.lang.Class.forName(Class.java:141)
> >>      java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
> >>      java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
> >>      org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
> >>      org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)
> 
> --
> Måns Rullgård
> mru@inprovide.com
> 
> 
> ---------------------------------------------------------------------
> 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: saving svg as jpeg on tomcat server

Posted by Måns Rullgård <mr...@inprovide.com>.
Thomas DeWeese <Th...@Kodak.com> writes:

> Hi Arian,
>
> Arian Hojat wrote:
>
>> I was wondering am i doing something screwy here?
>
>     I don't think so, but it looks like the tomcat
> JVM might be a little confused/corrupt.  What version
> of java is it using?
>
> Are you running tomcat with '-Djava.awt.headless=true'?
>
>     Normally you get a can't start AWT message but since
> this is the first time AWT is accessed it might be
> related.  Or was someone using the headless AWT replacement
> at one time?  I think that set a property that was supposed
> to replace the Sun Graphics engine.  Perhaps those classes
> weren't copied over?

I always get that exact error with fresh installs of Sun JDK and
Tomcat if -Djava.awt.headless=true is missing.  It took me a few
moments to figure it out the first time.

>> here is a stack trace on tomcat if anyone wants a look:
>> java.lang.NoClassDefFoundError
>> 	java.lang.Class.forName0(Native Method)
>> 	java.lang.Class.forName(Class.java:141)
>> 	java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
>> 	java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
>> 	org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
>> 	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)

-- 
Måns Rullgård
mru@inprovide.com


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


Re: saving svg as jpeg on tomcat server

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Arian,

Arian Hojat wrote:

> I was wondering am i doing something screwy here?

    I don't think so, but it looks like the tomcat
JVM might be a little confused/corrupt.  What version
of java is it using?

Are you running tomcat with '-Djava.awt.headless=true'?

    Normally you get a can't start AWT message but since
this is the first time AWT is accessed it might be
related.  Or was someone using the headless AWT replacement
at one time?  I think that set a property that was supposed
to replace the Sun Graphics engine.  Perhaps those classes
weren't copied over?

> here is a stack trace on tomcat if anyone wants a look:
> 
> java.lang.NoClassDefFoundError
> 	java.lang.Class.forName0(Native Method)
> 	java.lang.Class.forName(Class.java:141)
> 	java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
> 	java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
> 	org.apache.batik.ext.awt.image.GraphicsUtil.createGraphics(Unknown Source)
> 	org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(Unknown Source)

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