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 Geoffrey <jc...@hotmail.com> on 2004/04/15 21:46:14 UTC

JDom's Element to PDF through FOP

Hi,

I 've read the guide on how to create a pdf file from an xml file.
Problem is that this needs a StreamSource from an InputStream from the xml
file.
In my application I would like to directly export to a pdf file, coming from
jdom.org's Element or Document.
I found out how to create an xml file from JDom's Document (based on an
Element),
but this relies on an outputstream.

Is there a FilterOutputStream in FOP I can configure for PDF and chain to a
FileOutputStream and use it in JDom?

Thanks for any and all help,
Geoffrey




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


Re: JDom's Element to PDF through FOP

Posted by Tomasz Pik <pi...@ais.pl>.
Geoffrey wrote:

> Hi,
> 
> I 've read the guide on how to create a pdf file from an xml file.
> Problem is that this needs a StreamSource from an InputStream from the xml
> file.
> In my application I would like to directly export to a pdf file, coming from
> jdom.org's Element or Document.
> I found out how to create an xml file from JDom's Document (based on an
> Element),
> but this relies on an outputstream.

Sorry for non-precise hint but I think you should use
identity XSLT transform to 'translate' JDOM to SAX exents
(so JDOMSource and SAXResult).

Something like:

Driver driver = new Driver();

driver.initialize();

// Setup Renderer (output format)
driver.setRenderer(Driver.RENDER_PDF);

// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
   driver.setOutputStream(out);

   // Setup XSLT
   TransformerFactory factory = TransformerFactory.newInstance();
   // Identity transformation
   Transformer transformer = factory.newTransformer();

   // Setup input for XSLT transformation
   Source src = new JDOMSource(yourObject);

   // Resulting SAX events (the generated FO) must be piped
   // through to FOP
   Result res = new SAXResult(driver.getContentHandler());

   // Start XSLT transformation and FOP processing
   transformer.transform(src, res);
} finally {
   out.close();
}

HTH,
Tomek

PS: 
http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleXML2PDF.java?rev=1.7&view=auto


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


RE: JDom's Element to PDF through FOP

Posted by "Andreas L. Delmelle" <a_...@pandora.be>.
> -----Original Message-----
> From: Geoffrey
>
> Is there a FilterOutputStream in FOP I can configure for PDF and
> chain to a
> FileOutputStream and use it in JDom?
>

Hi,

Not entirely sure what your intention is, but IIC you simply want to output
the XML file to PDF? Raw copy? Like you would get when you send it to a
printer?

Remember FOP is a tool for rendering XSL-FO (--not: XML) to different output
formats, so I'm afraid it's going to take a little more than just connecting
streams...
What you need isn't some special OutputStream, but an XSL-FO template that
'pretty-prints' the XML input.

But this is all supposing I got your initial intention correctly... did I?


Cheers,

Andreas


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