xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anthony Ikeda <anthony.ik...@proxima-tech.com>
Subject Formatting PDF's
Date Mon, 29 Jan 2001 09:26:34 GMT
Okay, I have the code laid out and the XML/XSL docs.

Problem is when I go to render the document I get a
"org.apache.fop.apps.FOPException" without any description.

My main goal is to render a PDF document and then send it to a calling JSP.
Here is my class that does the conversions:

import java.io.*;
import java.util.HashMap;
import org.xml.sax.*;
import javax.servlet.*;
import javax.servlet.jsp.JspWriter;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;
import org.apache.fop.messaging.MessageHandler;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTProcessor;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTResultTarget;
...

  public void transformPDF(PrintWriter out){
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    if(xmlFile!=null&&!xmlFile.equals("")){
      try{
	FileInputStream fis = new FileInputStream(xmlFile);
	int c;
	while((c = fis.read())!=-1){
	xmlStr+=(char)c;
	}
      }
      catch(IOException ioe){
	System.out.println("IO Error: "+ioe);
      }
    }

    if(xslFile!=null&&!xslFile.equals("")){
      /** Load the file and set it as a string object
       *  If a file is set as the xsl source, then this class will load the
file
       *  otherwise it is skipped and the default string value is used.
       */
      FileInputStream fis=null;

      try{
	fis = new FileInputStream(xslFile);
	int c;
	while((c = fis.read())!=-1){
	xslStr+=(char)c;
	}
	fis.close();
      } catch(IOException ioe){
	System.out.println("IO Error: "+ioe);
	try{
	  fis.close();
	} catch(IOException ioeInner){
	  System.out.println("Error closing file: "+ioe);
	}
      }
    }

    XMLReader parser = null;

    try{
      parser =
(XMLReader)Class.forName("org.apache.xerces.parsers.SAXParser").newInstance(
);
    }catch(ClassNotFoundException cnfe){
      MessageHandler.logln("Unable to find parser:
org.apache.xerces.parsers.SAXParser");
    } catch(ClassCastException cce){
      MessageHandler.logln("Unable to create parser:
org.apache.xerces.parsers.SAXParser");
      MessageHandler.logln("ClassCastException caught! "+cce);
    } catch(IllegalAccessException iae){
      MessageHandler.logln("IllegalAccessException caught! "+iae);
    } catch(InstantiationException ie){
      MessageHandler.logln("InsantiationException caught! "+ie);
    }

    try{
      parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
    } catch(SAXException se){
      MessageHandler.logln("Error in setting up parser feature
namespace-prefixes.");
      MessageHandler.logln("You need a parser that supports SAX2.");
      System.exit(1);
    }

    try{
      StringWriter writer = new StringWriter();
      StringReader reader;
      StringReader strrdXML = new StringReader(xmlStr);
      StringReader strrdXSL = new StringReader(xslStr);

      MessageHandler.logln("Transforming code...");

      XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
      XSLTInputSource xmlSource = new XSLTInputSource(strrdXML);
      XSLTInputSource xslSource = new XSLTInputSource(strrdXSL);
      XSLTResultTarget pdfResult = new XSLTResultTarget(writer);
      processor.process(xmlSource, xslSource, pdfResult);

      reader = new StringReader(writer.toString());

      writer.flush();
      writer.close();

      Driver driver = new Driver();
 
driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",Version.getVersio
n());
      driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
      driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
 
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
      driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");

      driver.setOutputStream(outStream);
      driver.buildFOTree(parser,new InputSource(reader));
      reader.close();
      driver.format();
      driver.render();

      out.print(outStream.toString());

      xmlStr="";
      xslStr="";
      xslFile="";
      xmlFile="";
    } catch(Exception e){ System.out.println("PDF transform error..."+e);}
  }
...

Once called everything seems to go alright up until
driver.buildFOTree(parser,new InputSource(reader)); when the class casts the
exception.

Here is the output:

Transforming code...
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
Unknown tag in configuration file:
using renderer org.apache.fop.render.pdf.PDFRenderer
using element mapping org.apache.fop.fo.StandardElementMapping
using element mapping org.apache.fop.svg.SVGElementMapping
using property list mapping org.apache.fop.fo.StandardPropertyListMapping
using property list mapping org.apache.fop.svg.SVGPropertyListMapping
building formatting object tree
WARNING: Unknown formatting object ^
PDF transform error...org.apache.fop.apps.FOPException

I would expect FOP to skip any unknown formatting objects or does this need
to be declared expilicitly?

Anyone have any ideas?

Cheers,
Anthony Ikeda,
Web Application Developer,
Proxima Technology,

Level 13,
181 Miller Street,
North Sydney
Australia


PH: +612-9458-1718
Mob: 041 624 5143


Mime
View raw message