RE: Difficulties embedding FOP by firing SAX events myself

2001-11-15 Thread Smith, Paul

That is a much more sensible than messing about with pretend XMLReaders.

Cheers

---
Paul Smith


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: 15 November 2001 13:55
> To: [EMAIL PROTECTED]
> Subject: Re: Difficulties embedding FOP by firing SAX events myself
> 
> 
> 
> This is the code I use to get the handler.  I don't set the 
> input stream at
> all.  The setup order is hightly dependent.  This works on 0.20.2.
> 
> // THIS IS JUST SOME SET UP CODE
> // set up Logger
> Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
> PatternFormatter formatter = new PatternFormatter( "
> [%{priority}]:%{message}\n%{throwable}" );
> LogTarget target = new StreamTarget(System.out, formatter);
> hierarchy.setDefaultLogTarget(target);
> Logger log = hierarchy.getLoggerFor("fop");
> // get output stream one way or
> FileOutputStream out = new FileOutputStream( "filename.pdf" );
> 
> // HERE's THE CODE YOU NEED
> Driver driver = new Driver();
> driver.setOutputStream(out);
> driver.setLogger( log );
> driver.setRenderer( driver.RENDER_PDF );
> DefaultHandler handler = (DefaultHandler) 
> driver.getContentHandler() );
> handler.startDocument();
> ...
> handler.endDocument();
> out.close(); 


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




Re: Difficulties embedding FOP by firing SAX events myself

2001-11-15 Thread jthaemlitz


This is the code I use to get the handler.  I don't set the input stream at
all.  The setup order is hightly dependent.  This works on 0.20.2.

// THIS IS JUST SOME SET UP CODE
// set up Logger
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
PatternFormatter formatter = new PatternFormatter( "
[%{priority}]:%{message}\n%{throwable}" );
LogTarget target = new StreamTarget(System.out, formatter);
hierarchy.setDefaultLogTarget(target);
Logger log = hierarchy.getLoggerFor("fop");
// get output stream one way or
FileOutputStream out = new FileOutputStream( "filename.pdf" );

// HERE's THE CODE YOU NEED
Driver driver = new Driver();
driver.setOutputStream(out);
driver.setLogger( log );
driver.setRenderer( driver.RENDER_PDF );
DefaultHandler handler = (DefaultHandler) driver.getContentHandler() );
handler.startDocument();
...
handler.endDocument();
out.close();




   
  
fop-dev-return-11540-jthaemlitz=oreillyauto.com@XML.   
  
APACHE.ORG To: 
"Fop-Dev (E-mail)" <[EMAIL PROTECTED]>   
   cc: 
"Smith, Paul" <[EMAIL PROTECTED]>
11/15/01 06:10 AM  
Subject: Difficulties embedding FOP by firing SAX 
Please respond to fop-dev   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:

INFO10058   [foRender] (): building formatting object tree
DEBUG   10058   [fop ] (): setting up fonts
INFO10058   [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:

RE: Difficulties embedding FOP by firing SAX events myself

2001-11-15 Thread Smith, Paul

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:
> 
> 
> // 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);
> 
> 
> Now you can use th as a ContentHandler and fire the events on it!
> 
> 
>   pdf.close();
> }
> 
> 
> 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:
> 
> INFO10058   [foRender] (): building formatting object tree
> DEBUG   10058   [fop ] (): setting up fonts
> INFO10058   [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.

**