xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Tracey Zellmann" <tracey.zellm...@gmail.com>
Subject getting FOP to work with Java using 0.94
Date Thu, 01 Nov 2007 23:42:58 GMT
I was using 0.93 successfully some time ago, and I have another
application to use,
so I downloaded 0.94.

I am using Java 1.5.0_11

I tried to set things up correctly, but the PDF I generated can't be
read by Adobe Reader 8. I get a message that the file has been damaged
and can't be repaired.

I have some code that reads a source document, builds an Fop from a
FopFactory using MimeConstants.MIME_PDF and an OutputStream. I build a
Transformer from a TransformerFactory using an XSLT file, get a
SAXResult from the fop, and then transform the source into the result.

I have tried a very simple style sheet but no success.

Can anyone help me understand what is wrong, or point me to a basic
example that will work with the new version?

Here is the code:

               DocumentBuilderFactory dbf =
               DocumentBuilder db = null;
               Document input = null;
               try {
                       db = dbf.newDocumentBuilder();
                       input = db.parse(new
               } catch (ParserConfigurationException e) { e.printStackTrace();
               } catch (SAXException e) { e.printStackTrace();
               } catch (IOException e) { e.printStackTrace(); }
               Source src = new DOMSource(input);
               FopFactory fopFactory = FopFactory.newInstance();
               OutputStream out = null;
               File outputDir = new File("output");
               File outputFile = new File(outputDir, "System.pdf");
               try {
                       out = new BufferedOutputStream(new
               } catch (FileNotFoundException e) {e.printStackTrace();}
               Fop fop = null;
               try {
                       fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
               } catch (FOPException e) { e.printStackTrace(); }
               File xsltFile = new File("xslt/module-fo.xslt");
               TransformerFactory trFactory = TransformerFactory.newInstance();
               Transformer transformer = null;
               try {
                       transformer = trFactory.newTransformer(new
               } catch (TransformerConfigurationException e)
               Result res = null;
               try {
                       res = new SAXResult(fop.getDefaultHandler());
               } catch (FOPException e) { e.printStackTrace(); }
               try {
                       transformer.transform(src, res);
               } catch (TransformerException e) { e.printStackTrace();}

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

View raw message