[jdom-interest] jdom and fop

Andres March Andres at eHealthContracts.com
Thu Oct 31 09:45:20 PST 2002


 I can only speak about what we do to deal with this incompatibility between JDOM and FOP.  We do a good deal of PDF generation using these two libraries and it is not the best usage but here is the relevant code snippet:

//xsl
  //System.out.println("using xsl file " + this.xsltFile);
  File xslFile = new File(xsltFile);
  Source xslSource = new StreamSource(xslFile);

  //Transformer
  TransformerFactory tFactory = TransformerFactory.newInstance();
  Transformer pdfTransformer = tFactory.newTransformer(xslSource);

  //xml
  Document root = this.getXMLDocument();
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  XMLOutputter xmlOutputter = new XMLOutputter();
  xmlOutputter.output(root, outputStream);
  InputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(outputStream.toByteArray()));
  Source xmlSource = new StreamSource(inputStream);

  //FOP
  org.apache.fop.configuration.Configuration.put("strokeSVGText", new Boolean(false));
  Driver driver = new Driver();
  driver.setRenderer(driver.RENDER_PDF);
  ByteArrayOutputStream foOut = new ByteArrayOutputStream();
  driver.setOutputStream(foOut);
  ContentHandler contentHandler = driver.getContentHandler();//creates AreaTree
  SAXResult saxResult = new SAXResult(contentHandler);
  //System.out.println("saxResult " + saxResult.FEATURE);
  pdfTransformer.transform(xmlSource, saxResult);


As you can see, we write everything out to an output stream using the XMLOutputter and then read it in again to create a StreamSource for the Transformer to use.  We tried lots of different things and this is the best we could come up with.  I'd like to hear Jason's opinion on it.

Andres.

Your sanity is a terrible thing to waste.

-----Original Message-----
From: Norrman Per
To: 'jdom-interest at jdom.org '
Sent: 10/31/2002 3:59 AM
Subject: RE: [jdom-interest] jdom and fop

Hi,

I'm not sure if this will work or not, but how about
converting your JDOM result document into an org.w3c.dom.Document
using org.jdom.output.DOMOutputter. Then use that as input
to the pdfDriver via org.apache.fop.tools.DocumentInputSource.

It seems like a long shot, but why not...

/pmn

###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft
Exchange.
For more information, connect to http://www.F-Secure.com/
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhost.com




More information about the jdom-interest mailing list