Unfortunately I am using Java 1.3.1, javax.xml.* doesn't make an appearance
until 1.4 so I can't use TransformerFactory.

---
Paul Smith

> -----Original Message-----
> From: Beer, Christian [mailto:[EMAIL PROTECTED]]
> Sent: 15 November 2001 13:14
> To: '[EMAIL PROTECTED]'
> Subject: AW: Difficulties embedding FOP by firing SAX events myself
> 
> 
> I did it this way:
> 
> <code>
> // FO --> PDF
> driver.reset();
> driver.setOutputStream(pdf);
> driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
> 
> TransformerFactory tFactory = TransformerFactory.newInstance();
> if (tFactory.getFeature(SAXSource.FEATURE) &&
> tFactory.getFeature(SAXResult.FEATURE)) {
>   SAXTransformerFactory saxTFactory = 
> ((SAXTransformerFactory)tFactory);
> 
>   TransformerHandler th = saxTFactory.newTransformerHandler(new
> StreamSource(xsl));
> 
>   // Create SAXResult based on FOP Driver content handler 
> which will accept
>   // SAX events and build FOP tree
>   SAXResult saxResult = new SAXResult(driver.getContentHandler());
> 
>   th.setResult(saxResult);
> <comment>
> 
> Now you can use th as a ContentHandler and fire the events on it!
> 
> </comment>
>   pdf.close();
> }
> </code>
> 
> Christian
> 
> -----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
> 
> 
> Hi,
> 
> 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,
> indenting));
>       ContentHandler handler = serializer.asContentHandler();
>       parser.setContentHandler(handler);
>       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 =
> Hierarchy.getDefaultHierarchy().getLoggerFor("foRender");
>       logger.setPriority(Priority.INFO);
>       driver.setLogger(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:
> 
> %PDF-1.3
> %ª«¬­
> 4 0 obj
> << /Type /Info
> /Producer (null) >>
> endobj
> 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:
> 
> %PDF-1.3
> %ª«¬­
> 4 0 obj
> << /Type /Info
> /Producer (FOP 0.20.1) >>
> endobj
> 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]
> 


*******************************************************************
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]

Reply via email to