You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Ozhan Hassan <oz...@io.mds.rmit.edu.au> on 2003/05/05 09:23:50 UTC

Problem rendering SVG

Hi,

I am experiencing some a weird problem while trying to render some SVG.
I have a simple java program which reads in an XML file and an XSLT
stylesheet (containing some SVG) and render it out to PDF. What happens is
my terminal just frezzes, and I can't kill the process or do anything
else. The process only hangs when I run my application, i.e. if I run fop
from the command line passing it the XSLT with the SVG, it works fine.

Here is SVG from the XSLT style sheet:

    <xsl:template name="DisplaySvg">
        <fo:instream-foreign-object>
            <svg:svg xmlns:svg="http://www.w3.org/2000/svg" 
            width = "300" height="200" viewBox="0 0 300 200" 
            xml:space="preserve">
              <svg:g style="fill:white; stroke:#000000">
                 <svg:line x1="0" y1="200" x2="0" y2="0"/>
                 <svg:line x1="0" y1="200" x2="200" y2="200"/>
                 <svg:rect x="10" y="150" width="20" height="50" 
                    style="fill:blue; stroke:#000000"/>
                 <svg:rect x="40" y="170" width="20" height="30" 
                    style="fill:black; stroke:#000000"/>
                 <svg:rect x="70" y="100" width="20" height="100" 
                    style="fill:green; stroke:#000000"/>
                 <svg:rect x="100" y="20" width="20" height="180" 
                    style="fill:yellow; stroke:#000000"/>
                 <svg:rect x="130" y="150" width="20" height="50" 
                    style="fill:red; stroke:#000000"/>
              </svg:g>
            </svg:svg>
        </fo:instream-foreign-object>
	</xsl:template> 

-------

The my java application which does what I explained above is:

import java.io.*;

// FOP libraries
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;
import org.apache.fop.messaging.MessageHandler;

import org.xml.sax.InputSource;
import org.apache.fop.apps.FOPException;

import org.apache.avalon.framework.logger.ConsoleLogger;  
import org.apache.avalon.framework.logger.Logger; 

import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.sax.*;


class RenderingEngineXsltSvg
{
    
    // number of PDFs to be generated
    static final int OUTPUT_SIZE = 1;
    static final String INPUT_XML = "statement.xml";
    static final String INPUT_XSLT = "toXslFoSVG.xslt";
    static final String INPUT_DIR = "../../tmp/input/";
    static final String OUTPUT_DIR = "../../tmp/output/";

    
    public static void main(String args[])
    {
        try
        {
            // only create the Transformer which reads the XSLT once
            Transformer transformer = TransformerFactory.newInstance()
                .newTransformer(new StreamSource(INPUT_DIR + INPUT_XSLT));
                
            for(int i = 1; i <= OUTPUT_SIZE; i++)
            {
                String fileName = INPUT_XML;
                int fileLength = fileName.length();
                
                fileName = fileName.substring(0, fileLength - 4);
                String outFileName = OUTPUT_DIR + fileName + i + ".pdf";
            
                    Driver driver = new Driver();
                    driver.setOutputStream(new
FileOutputStream(outFileName));
                    Logger logger = new
ConsoleLogger(ConsoleLogger.LEVEL_INFO);
                    MessageHandler.setScreenLogger(logger);
                    driver.setLogger(logger);
                    driver.setRenderer(Driver.RENDER_PDF);

                    transformer.transform(new 
                        StreamSource(INPUT_DIR + INPUT_XML),
                        new SAXResult(driver.getContentHandler()));

                System.out.println("***** GENERATED PDF: " + i + "
*****");
            }
        }
        catch (javax.xml.transform.TransformerConfigurationException ex)
        {
            System.err.println("Exception: " + ex.toString());
        }
        catch (javax.xml.transform.TransformerException ex)
        {
            System.err.println("Exception: " + ex.toString());
        }
        catch (IOException ex)
        {
            System.err.println("IO Exception: " + ex.toString());
        }

        // Everything is OK - exit
        System.exit(0);
    }
}

---

Any help would be appreciated.

Regards,
Ozhan

----------------------------
Ozhan Hassan
Multimedia Database Systems
RMIT University
Email: ozhan@mds.rmit.edu.au
Phone: 9925 4118


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Jeremias Maerki <de...@greenmail.ch>.
Ok, in this case take the examples/embedding/java/embedding/ExampleXML2PDF.java
and adjust it to your usecase. Check if it works with that. I've tested
it with your XSL snippet on my workstation and it worked.

On 07.05.2003 08:22:58 Ozhan Hassan wrote:
> Sorry, I forgot to mention that. I did try it with the log level set to
> LEVEL_DEBUG, but it made no difference. I didn't receive any additional
> output from using the standard LEVEL_INFO. I also have batik.jar in my
> classpath. Any other ideas?


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Jeremias Maerki <de...@greenmail.ch>.
Is that a headless server? In this case http://xml.apache.org/fop/faq.html#svg-headless
may help.

On 07.05.2003 08:45:32 Ozhan Hassan wrote:
> One more interesting point I should address. I have been running my
> application on a Solaris platform, where it has been crashing. However, I
> just tried running it on a Windows PC and it worked fine, didn't crash. I
> hope this is helpful to anyone who may know why this is.


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Ozhan Hassan <oz...@io.mds.rmit.edu.au>.
Hi,

One more interesting point I should address. I have been running my
application on a Solaris platform, where it has been crashing. However, I
just tried running it on a Windows PC and it worked fine, didn't crash. I
hope this is helpful to anyone who may know why this is.

Regards,
Ozhan

----------------------------
Ozhan Hassan
Multimedia Database Systems
RMIT University
Email: ozhan@mds.rmit.edu.au
Phone: 9925 4118

On Wed, 7 May 2003, Ozhan Hassan wrote:

> On Wed, 7 May 2003, Jeremias Maerki wrote:
> 
> > You didn't say whether setting the log level to LEVEL_DEBUG helped or
> > not. Even if your XSLT is ok, my suggestions still apply. I've found
> > bugs that way before. So if it's really the SVG that's having a problem
> > check if Batik is in the classpath and if you're using the version
> > that's coming with your FOP version.
> 
> Hi,
> 
> Sorry, I forgot to mention that. I did try it with the log level set to
> LEVEL_DEBUG, but it made no difference. I didn't receive any additional
> output from using the standard LEVEL_INFO. I also have batik.jar in my
> classpath. Any other ideas?
> 
> Regards,
> Ozhan
> 
> > 
> > On 07.05.2003 02:29:54 Ozhan Hassan wrote:
> > > I know that there is nothing wrong with the XSLT, including the SVG
> > > because if I run fop from the command line, passing it an XML file and the
> > > XSLT, it works fine. It only hangs when I run it via my application. I am
> > > guessing that maybe my application isn't setting a property which is
> > > needed, or something like that. If I comment out the SVG, my application
> > > runs fine. Does anyone know why this is happening?
> > 
> > 
> > 
> > Jeremias Maerki
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: fop-user-help@xml.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Ozhan Hassan <oz...@io.mds.rmit.edu.au>.
On Wed, 7 May 2003, Jeremias Maerki wrote:

> You didn't say whether setting the log level to LEVEL_DEBUG helped or
> not. Even if your XSLT is ok, my suggestions still apply. I've found
> bugs that way before. So if it's really the SVG that's having a problem
> check if Batik is in the classpath and if you're using the version
> that's coming with your FOP version.

Hi,

Sorry, I forgot to mention that. I did try it with the log level set to
LEVEL_DEBUG, but it made no difference. I didn't receive any additional
output from using the standard LEVEL_INFO. I also have batik.jar in my
classpath. Any other ideas?

Regards,
Ozhan

> 
> On 07.05.2003 02:29:54 Ozhan Hassan wrote:
> > I know that there is nothing wrong with the XSLT, including the SVG
> > because if I run fop from the command line, passing it an XML file and the
> > XSLT, it works fine. It only hangs when I run it via my application. I am
> > guessing that maybe my application isn't setting a property which is
> > needed, or something like that. If I comment out the SVG, my application
> > runs fine. Does anyone know why this is happening?
> 
> 
> 
> Jeremias Maerki
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Jeremias Maerki <de...@greenmail.ch>.
You didn't say whether setting the log level to LEVEL_DEBUG helped or
not. Even if your XSLT is ok, my suggestions still apply. I've found
bugs that way before. So if it's really the SVG that's having a problem
check if Batik is in the classpath and if you're using the version
that's coming with your FOP version.

On 07.05.2003 02:29:54 Ozhan Hassan wrote:
> I know that there is nothing wrong with the XSLT, including the SVG
> because if I run fop from the command line, passing it an XML file and the
> XSLT, it works fine. It only hangs when I run it via my application. I am
> guessing that maybe my application isn't setting a property which is
> needed, or something like that. If I comment out the SVG, my application
> runs fine. Does anyone know why this is happening?



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Ozhan Hassan <oz...@io.mds.rmit.edu.au>.
On Mon, 5 May 2003, Jeremias Maerki wrote:

> Try setting the log level to LEVEL_DEBUG and watch the log. Maybe that
> helps finding out what's wrong. Without actually running your code, I'd
> say it should be ok.
> 
> What you can also try is to disable the stylesheet (by using the
> identity transformer and loading an XSL:FO file). This helps narrow down
> the possibilities for errors. Also temporarily comment out the SVG code
> in your stylesheet to see if it has something to do with that.

I know that there is nothing wrong with the XSLT, including the SVG
because if I run fop from the command line, passing it an XML file and the
XSLT, it works fine. It only hangs when I run it via my application. I am
guessing that maybe my application isn't setting a property which is
needed, or something like that. If I comment out the SVG, my application
runs fine. Does anyone know why this is happening?

Regards.
Ozhan

> 
> On 05.05.2003 09:23:50 Ozhan Hassan wrote:
> > I am experiencing some a weird problem while trying to render some SVG.
> > I have a simple java program which reads in an XML file and an XSLT
> > stylesheet (containing some SVG) and render it out to PDF. What happens is
> > my terminal just frezzes, and I can't kill the process or do anything
> > else. The process only hangs when I run my application, i.e. if I run fop
> > from the command line passing it the XSLT with the SVG, it works fine.
> 
> <snip what="code"/>
> 
> 
> Jeremias Maerki
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Problem rendering SVG

Posted by Jeremias Maerki <de...@greenmail.ch>.
Try setting the log level to LEVEL_DEBUG and watch the log. Maybe that
helps finding out what's wrong. Without actually running your code, I'd
say it should be ok.

What you can also try is to disable the stylesheet (by using the
identity transformer and loading an XSL:FO file). This helps narrow down
the possibilities for errors. Also temporarily comment out the SVG code
in your stylesheet to see if it has something to do with that.

On 05.05.2003 09:23:50 Ozhan Hassan wrote:
> I am experiencing some a weird problem while trying to render some SVG.
> I have a simple java program which reads in an XML file and an XSLT
> stylesheet (containing some SVG) and render it out to PDF. What happens is
> my terminal just frezzes, and I can't kill the process or do anything
> else. The process only hangs when I run my application, i.e. if I run fop
> from the command line passing it the XSLT with the SVG, it works fine.

<snip what="code"/>


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org