[jdom-interest] DOMOutputter and FOP

Stefan Neumann stefan.neumann at netgrafics.de
Wed Apr 18 05:27:49 PDT 2001


Hi,

I'm already using JDOM to create data-bound HTML-Forms in two
languages out of XML. In the following example I tried to
create a pdf-file using one of the FOP-examples(simple.fo).
When running it with "java org.apache.fop.apps.CommandLine
 simple.fo simple.pdf" on the command line everything is fine,
but using the Driver buildFOTree failes (NullPointerException).
Seems to me that this method doesn't like the DOM created by
the DOMOutputter of JDOM.

import java.io.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

import org.apache.fop.apps.*;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;

public class createPdf
{

public static void main(String[] args)
	{
		org.w3c.dom.Document w3doc = null;
		try
		{
		  SAXBuilder builder = new SAXBuilder();
		  Document doc = builder.build(new File("simple.fo"));
		  DOMOutputter domout = new DOMOutputter();
		  w3doc = domout.output(doc);
		}
		catch (JDOMException jde)
		{
		  System.out.println("JDOMException:" + jde.getMessage());
		}
		try
		{
		  File f = new File("simple.pdf");
		  FileOutputStream fout = new FileOutputStream(f);
		  Driver fopdrv = new Driver();
		  fopdrv.setRenderer("org.apache.fop.render.pdf.PDFRenderer",
Version.getVersion());
		  fopdrv.addElementMapping("org.apache.fop.fo.StandardElementMapping");
		  fopdrv.addElementMapping("org.apache.fop.svg.SVGElementMapping");
		  fopdrv.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
		  fopdrv.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
		  fopdrv.setOutputStream(fout);
		  fopdrv.buildFOTree(w3doc);
		  fopdrv.format();
		  fopdrv.render();
		}
		catch (Exception e)
		{
		  System.out.println(e.getMessage());
		}
	}
}

I tried to specify a DOMAdapter, but regardless of the fact that I dont't
know
how such a string would look like (help!) the Compiler doesn't let me use a
string there anyway: wrong number of arguments in constructor.
Anyone any idea?

Thanks!




More information about the jdom-interest mailing list