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 "Savino, Matt C" <Ma...@questdiagnostics.com> on 2001/09/26 01:27:32 UTC

RE: FOP WARNING - Please Help!

Shkuro, I have tried to replicate your solution and I still get strange
errors. Here is the error I get:

D:\Precision\RV40_Working\pvh>java FOtoPDF
building formatting object tree
building formatting object tree
javax.xml.transform.TransformerException
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1212)
        at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
479)
        at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1118)
        at FOtoPDF.applyFop(FOtoPDF.java:143)
        at FOtoPDF.main(FOtoPDF.java:41)
---------
java.lang.NullPointerException
        at
org.apache.fop.fo.FOTreeBuilder.startDocument(FOTreeBuilder.java:167)
        at
org.apache.xalan.transformer.QueuedStartDocument.flush(QueuedStartDocument.j
ava:108)
        at
org.apache.xalan.transformer.ResultTreeHandler.flushPending(ResultTreeHandle
r.java:758)
        at
org.apache.xalan.transformer.ResultTreeHandler.startElement(ResultTreeHandle
r.java:245)
        at
org.apache.xalan.transformer.ResultTreeHandler.startElement(ResultTreeHandle
r.java:209)
        at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
704)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2154)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2097)
        at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
Impl.java:2029)
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1189)
        at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
479)
        at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1118)
        at FOtoPDF.applyFop(FOtoPDF.java:143)
        at FOtoPDF.main(FOtoPDF.java:41)

It looks like maybe it's trying to build the formatting tree twice? 

Here is my code:
            DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();
            dFactory.setNamespaceAware(true);
            DocumentBuilder dBuilder = dFactory.newDocumentBuilder();

            org.w3c.dom.Document xmlDoc = dBuilder.parse(xmlFilename);
            DOMSource xmlDomSource = new DOMSource(xmlDoc);

            org.w3c.dom.Document xslDoc = dBuilder.parse(xslFilename);
            DOMSource xslDomSource = new DOMSource(xslDoc);

            TransformerFactory tFactory = TransformerFactory.newInstance();
            javax.xml.transform.Templates templates =
tFactory.newTemplates(xslDomSource);
            Transformer transformer = templates.newTransformer();

            org.apache.fop.apps.Driver driver = new
org.apache.fop.apps.Driver();
            driver.setErrorDump(true);
            driver.setRenderer(driver.RENDER_PDF);
            driver.setOutputStream(new FileOutputStream(pdfFilename));

            javax.xml.transform.sax.SAXResult saxResult = new
javax.xml.transform.sax.SAXResult( driver.getContentHandler() );
            transformer.transform(xmlDomSource, saxResult);

Someone also said this may be fixed in the latest CVS. I downloaded
Fop-0.20.1-src.tar.gz on 9/17/01. Is there something more recent? I only ask
because my ridiculous company still hasn't restored our internet access
since Nimda.

I would also be happy if I could get render(dom) working when applied to a
dynamically-generated DOM object. I can get it to work on a DOM generated
from a file, but not on the same DOM generated from an XSLT transform. I'd
rather not have to save my XSLT output to a temp file every time I want to
generate a PDF document. I described this case thoroughly at the end of the
'Does render(dom) actually work?' thread.

I combine this code with what I have above and render(dom) works fine:

           File foFile = new File(foFilename);
           StreamResult streamResult = new StreamResult(foFile);

           transformer.transform(xmlDomSource, streamResult);
           org.w3c.dom.Document foDoc = dBuilder.parse(foFilename);
           DOMSource foDomSource = new DOMSource(foDoc);
	     ...
           driver.render(foDoc);

But if I try it this way:

            DOMResult domResult = new DOMResult();

            transformer.transform(xmlDomSource, domResult);
            org.w3c.dom.Document foOutDoc =
(org.w3c.dom.Document)domResult.getNode();
	      ...
            driver.render(foOutDoc);

I get this error:

building formatting object tree
setting up fonts
java.lang.NullPointerException
        at java.util.Hashtable.get(Hashtable.java:320)
        at
org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:191)
        at
org.apache.fop.tools.DocumentReader.parse(DocumentReader.java:444)
        at org.apache.fop.apps.Driver.render(Driver.java:449)
        at FOtoPDF.applyFop(FOtoPDF.java:131)
        at FOtoPDF.main(FOtoPDF.java:41)


I have verified that the content of the file-generated DOM object and the
XSLT-generated DOM object are exactly the same. The only difference I could
find was that the DocumentType.getName() method returned 'fo:root' for the
file-generated DOM object whereas the entire DocumentType was null for the
XSLT-generated DOM object. 

I also tried this third method (with XSLTInputHandler and TraxInputHandler):
            
	org.apache.fop.apps.XSLTInputHandler xsltIH = new
org.apache.fop.apps.XSLTInputHandler (xmlFile, xsltFile);
      driver.render(xsltIH.getParser(), xsltIH.getInputSource());

And I get these errors:

using SAX parser org.apache.xerces.parsers.SAXParser
building formatting object tree
setting up fonts
WARNING: Unknown formatting object ^layout-master-set
WARNING: Unknown formatting object ^simple-page-master
WARNING: Unknown formatting object ^region-body
WARNING: Unknown formatting object ^region-before
WARNING: Unknown formatting object ^region-after
WARNING: Unknown formatting object ^page-sequence
WARNING: Unknown formatting object ^static-content
WARNING: Unknown formatting object ^block
WARNING: Unknown formatting object ^table
WARNING: Unknown formatting object ^table-column
WARNING: Unknown formatting object ^table-body
WARNING: Unknown formatting object ^table-row
WARNING: Unknown formatting object ^table-cell
WARNING: Unknown formatting object ^page-number
WARNING: Unknown formatting object ^flow
Parsing of document complete, stopping renderer
Initial heap size: 1818Kb
Current heap size: 1875Kb
Total memory used: 57Kb
  Memory use is indicative; no GC was performed
  These figures should not be used comparatively
Total time used: 281ms
Pages rendererd: 0
Parsing of document complete, stopping renderer
Initial heap size: 1818Kb
Current heap size: 1884Kb
Total memory used: 66Kb
  Memory use is indicative; no GC was performed
  These figures should not be used comparatively
Total time used: 343ms
Pages rendererd: 0
org.apache.fop.apps.FOPException: / by zero
        at org.apache.fop.apps.Driver.render(Driver.java:429)
        at FOtoPDF.applyFop(FOtoPDF.java:158)
        at FOtoPDF.main(FOtoPDF.java:41)

---------

javax.xml.transform.TransformerException: / by zero
        at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:137)
        at org.apache.fop.apps.Driver.render(Driver.java:424)
        at FOtoPDF.applyFop(FOtoPDF.java:158)
        at FOtoPDF.main(FOtoPDF.java:41)

---------

javax.xml.transform.TransformerException: / by zero
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1212)
        at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
        at java.lang.Thread.run(Thread.java:484)
---------
java.lang.ArithmeticException: / by zero
        at
org.apache.fop.apps.StreamRenderer.stopRenderer(StreamRenderer.java:146)
        at
org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:173)
        at
org.apache.xalan.transformer.ResultTreeHandler.endDocument(ResultTreeHandler
.java:180)
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1194)
        at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
        at java.lang.Thread.run(Thread.java:484)


It was suggested make sure the document URI is being given to FOP. How do I
do this in 0.20.1?

I also saw these two suggestions:
1. Misspelled the URI for the xmlns:fo attribute, or
2. Did not use the "fo:" prefix on the root element while the default
namespace is not the XSL-FO namespace.

Could either of them possibly apply to my situation? Here is my root
element: 
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

I'm wondering if there is something weird going on here with DOM level 2? Or
possibly some namespace or URI issues? I admit I'm no XML guru.

I really stuck my neck out to get us to use FOP on this project instead of
Root River. I promise I'll send a big fruit basket to anyone who can provide
with some code for either of these three solutions that actually works.

Thank you very much,
Matt Savino

949-728-4832


> -----Original Message-----
> From: Shkuro, Yuri [mailto:Yuri.Shkuro@gs.com]
> Sent: Monday, September 24, 2001 7:04 AM
> To: 'fop-dev@xml.apache.org'
> Subject: RE: FOP WARNING
> 
> 
> Two problem with this approach.  First, you are using a lot 
> of memory to
> store
> intermediate XML result in a string buffer.  Second, you have 
> to parse that
> XML
> again (FOP will do it for you, but it takes time).  A better 
> solution, as I
> already
> said before, is to register FOP as a receiver of SAX events 
> fired by XALAN
> on the first transformation - this was you eliminate both 
> problems and do
> all
> your work in one pass.  Just create a Transformer from the 
> stylesheet and do
> 
>  // 3. Create FOP driver and set rendering mode and output stream
>  org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();
>  driver.setRenderer(driver.RENDER_PDF);
>  driver.setOutputStream( <whatever you writing to> );
> 
>  // 4. Create SAXResult based on FOP Driver content handler which 
>  // will accept SAX events and build FOP tree
>  javax.xml.transform.sax.SAXResult saxResult =
>    new javax.xml.transform.sax.SAXResult( 
> driver.getContentHandler() );
> 
>  // 5. Use the Transformer to transform an XML Source and 
> send the output 
>  //     to a Result object.
>  //    Implicitely it will create the FOP tree by firing SAX events
>  transformer.transform( <whatever XML source you have>, saxResult );
> 
> 
> YS
> -----Original Message-----
> From: Semprini Davide [mailto:davide.semprini@cineca.it]
> Sent: Monday, September 24, 2001 9:42 AM
> To: fop-dev@xml.apache.org
> Subject: Re: FOP WARNING
> 
> 
> Okay,
> 
> The example that I give is only to explain
> that you can perform the PDF in two distinc phase
> 1) perform a trasformation 
> 2) use driver
> 
> You can use the "tranform method" 
> with input like Dynamic xml (Dom Document) or urlXML  
> and getting out a fo (Dom Document) or Writer object
> YOU HAVE A LOT OF TRANSFORM TO USE!!!!!!
> YOU HAVE TO SEE THE APIDOC FOR THE
> COMPLETE DOCUMENTATION!!!!
> 
> For example in my project I use
> xalan transform and with some
> conversion I use the Fop driver
> and my XML is dynamic.
> WITH Transformer XALAN: 
> StringWriter SstringWriter = new StringWriter();
> /* this is the fo file */
>  StreamResult SstreamResult = new StreamResult(SstringWriter);
> 
> transformer.transform(SstreamSourceXML, SstreamResult)
> 
> /* convert the fo file in a right format for driver
>  ByteArrayOutputStream outPDF = new ByteArrayOutputStream();
>  SResult = SstringWriter.toString();               
>  ByteArrayInputStream str = new 
> ByteArrayInputStream(SResult.getBytes());
> 
>  Driver driver = new Driver(new InputSource(str), outPDF);
> 
> 
> Is this performance????? I think yes!!
> 
> Bye
>   
> 
> Amit wrote:
> 
> Looking at your code I am guessing that you wrote the fo file 
> out to the
> filesystem and then used the driver to convert it to PDF...how is
> performance on that? 
> Instead of writing the file out to the file system did you 
> try converting
> into some sorta stream and use the driver?? 
> thanks for your help 
> Amit 
> Semprini Davide wrote: 
> Hi, 
> I have had the same problem!!!!!!!! 
> Nobody give me a response! 
> This code in FOP Home page don't work (for me!) !!!!! 
> Driver driver = new Driver();  driver.setRenderer(Driver.RENDER_PDF);
> InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile);
> XMLReader parser = inputHandler.getParser();  
> driver.setOutputStream(new
> FileOutputStream(outFile));  driver.render(parser,
> inputHandler.getInputSource());
> 
> I have solved the problem using 2 phase: 
> 1) generate the transformation using XSLTrasform, 
> Xalan1Transform etc...
> (you can choose) 
> code: 
> XSLTransform traXSLT = new XSLTransform(); 
> traXSLT.transform(urlXML, urlXSL, urlFoFile); 
> You can choose 4 transform type (see the api documentation) 
> 2) Apply the result at the driver 
> FileInputStream file = new FileInputStream(urlFoFile); 
>     response.setContentType("application/pdf"); 
>     Driver driver = new Driver(new InputSource(file), out); 
>     driver.setRenderer(Driver.RENDER_PDF); 
>     driver.run(); 
>     byte[] content = out.toByteArray(); 
>     response.setContentLength(content.length); 
>     response.getOutputStream().write(content); 
>     response.getOutputStream().flush(); 
> THIS CODE WORK FINE!!! 
> Bye 
>   
>   
> Amit wrote: 
> I am trying to generate PDFs using FOP-0.20.1. The input 
> files are xmland
> xsl filesI am using JRun3.0 with java1.2.2Here is the error I 
> getWARNING:
> Unknown formatting object ^rootAnybody any
> ideas?--------------------------------------------------------
> -------------T
> o unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.orgFor 
> additional
> commands, email: fop-dev-help@xml.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org