You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Smith, Paul" <pa...@uk.appl.net> on 2001/11/15 13:10:40 UTC

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: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org