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:

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