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 Marianne von den Driesch und Viktor Goebel <m....@gto-nordwest.de> on 2002/04/12 08:50:17 UTC

problem with embedding fop solved

We used the Oracle JDeveloper to edit the Java application. Some of the 
libraries supplied by FOP are already available in the Oracle Java Packages. 
We had to remove the Oracle Java Packages and to add only the FOP Packages 
and the problems were solved.

The code from Mr.Fischer worked:

import org.apache.log.*;

public class EmbeddingFOP_1
{
  public static void main(String[] args) throws Exception 
  {
    try 
    {
      javax.xml.transform.stream.StreamSource xmlSource=new 
javax.xml.transform.stream.StreamSource(new java.io.File("D:\\glossary.xml"));
      javax.xml.transform.stream.StreamSource xslSource=new 
javax.xml.transform.stream.StreamSource(new java.io.File("D:\\glossary.xsl"));
      javax.xml.transform.Transformer 
transformer=javax.xml.transform.TransformerFactory.newInstance().newTransformer(xslSource);

      Logger log;
      Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
      log = hierarchy.getLoggerFor("fop");
      log.setPriority(Priority.WARN);

      org.apache.fop.apps.Driver driver=new org.apache.fop.apps.Driver();
      driver.setLogger(log);
      driver.setOutputStream(new 
java.io.FileOutputStream("D:\\glossary.pdf"));
      driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
      transformer.transform(xmlSource,new 
javax.xml.transform.sax.SAXResult(driver.getContentHandler()));
    }
    catch( Exception e ) 
    {
      e.printStackTrace(System.out);
    }
  }
}

The following code also worked:

import java.io.*;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;
import org.apache.fop.apps.*;
import org.apache.log.*;

public class EmbeddingFOP_2 
{
    public static void main(String[] args) throws Exception 
    {
    	File fxml=new File("D:\\glossary.xml");
    	File fxsl=new File("D:\\glossary.xsl");
    	File fpdf=new File("D:\\glossary.pdf");

	Logger log;
    	Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
    	log = hierarchy.getLoggerFor("fop");
    	log.setPriority(Priority.WARN);

	Driver dr=new Driver();
    	dr.setLogger(log);
    	dr.setRenderer(Driver.RENDER_PDF);
    	InputHandler ih=new XSLTInputHandler(fxml,fxsl);
    	XMLReader p=ih.getParser();
    	dr.setOutputStream(new FileOutputStream(fpdf));
    	dr.render(p,ih.getInputSource());
    }
}



Thanks to all for the help,
Marianne and Viktor.