I did it this way:

// FO --> PDF

TransformerFactory tFactory = TransformerFactory.newInstance();
if (tFactory.getFeature(SAXSource.FEATURE) &&
tFactory.getFeature(SAXResult.FEATURE)) {
  SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)tFactory);

  TransformerHandler th = saxTFactory.newTransformerHandler(new

  // Create SAXResult based on FOP Driver content handler which will accept
  // SAX events and build FOP tree
  SAXResult saxResult = new SAXResult(driver.getContentHandler());


Now you can use th as a ContentHandler and fire the events on it!



-----Ursprüngliche Nachricht-----
Von: Smith, Paul [mailto:[EMAIL PROTECTED]]
Gesendet: Donnerstag, 15. November 2001 13:11
An: Fop-Dev (E-mail)
Cc: Smith, Paul
Betreff: Difficulties embedding FOP by firing SAX events myself


I am trying to embed FOP within my own Java application as described in
http://xml.apache.org/fop/embedding.html, specifically the third method:
"calling getContentHandler() and firing the SAX events yourself" and I am
running into difficulties!

I have a class called MyParser which fires the required events (it
implements XMLReader). Its parse method that calls SAX events on
ContentHandler and ignores the InputStream. If I do:
(I have simplifed the code samples so their maybe a few typos)

        MyParser parser = new MyParser();
        XMLSerializer serializer = new XMLSerializer(new
FileOutputStream("output.fo"), new OutputFormat(method, encoding,
        ContentHandler handler = serializer.asContentHandler();
        parser.parse(new InputStream());

Then I can produce a well formed XSL-FO file that validates against the DTD
provided by N. Grigoriev from RenderX. Running fop on this file eg. "fop
output.fo output.pdf", generates output.pdf successfully.

HOWEVER, If I try and embed FOP by doing:

        Driver driver = new Driver();
        driver.setOutputStream(new FileOutputStream("output.pdf");
        driver.setInputSource(new InputSource());
        Logger logger =
        MyParser parser = new MyParser();
        driver.render(parser, new InputSource());
FOP generates output.pdf but when opened in Acrobat Reader I get "There was
an error opening this document. Could not repair file."
Closer inspection shows that the PDF has not been correctly generated at
all. The first 9 lines look like:

4 0 obj
<< /Type /Info
/Producer (null) >>
5 0 obj
<< /Length 235 /Filter /FlateDecode 

where as the first 9 lines of the PDF generated by running FOP from the
command line look like:

4 0 obj
<< /Type /Info
/Producer (FOP 0.20.1) >>
5 0 obj
<< /Length 296 /Filter [ /ASCII85Decode /FlateDecode ]

During driver.render the logger prints out:

INFO    10058   [foRender] (): building formatting object tree
DEBUG   10058   [fop     ] (): setting up fonts
INFO    10058   [foRender] (): [1]

Any help you can offer is much appreciated. Thanks in advance

Paul Smith

DISCLAIMER: The information contained in this email
 is confidential and is intended solely for the use of the
 named addressee.  Access, copying or re-use of the
 information in it by any other person is not authorised.


To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to