xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Prashant Neginahal <prashu.n...@gmail.com>
Subject PDF from Java Value Objects
Date Fri, 19 Aug 2011 09:29:50 GMT


I am trying to explore this library to create PDF documents and gone through
all the examples.

In my application, we query database and get the value objects (java beans)
and out of this we need to create PDF files. I looked at ExampleJavatoPDF,
for me it looks too much of code (with SAXSource). I was thinking to use
JAXB annotations (jaxb is shipped with JDK1.6) and generate XML stream on
the fly and apply XSL to generate PDF.

The code looks as below.

JAXBContext context = JAXBContext.newInstance(valueObj.getClass());
Marshaller m = context.createMarshaller();

ByteArrayOutputStream xmlOut = new ByteArrayOutputStream();
m.marshal(valueObj, xmlOut);
byte[] o = xmlOut.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(o);

Source src = new StreamSource(in);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);

It works fine. My question is, is it best practice to generate PDF files
from Java Objects? Is there a better way? Can we generate XSL-FO from Java

Thanks in advance.

View this message in context: http://old.nabble.com/PDF-from-Java-Value-Objects-tp32293814p32293814.html
Sent from the FOP - Users mailing list archive at Nabble.com.

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

View raw message