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 Bracchi Cabannes Christophe <ch...@ac-toulouse.fr> on 2001/04/23 10:37:11 UTC

Re: Help: How to transform XSLTResultTarget object to Document Object for Driver buildFoTree()

Fr : Peut �tre que ceci vous aidera.    J'ai en entr� une chaine xml et
le chemin d'un fichier xsl, je produit d'abord une sortie fo, et ensuite,
� partir de ce flux, je produit la sortie pdf qui repart vers le client.
Ceci ce passe dans le cadre d'une servlet. Ceci marche tr�s bien et
utilise xalan-2.0.0.jar, xerces-1.2.3.jar et fop.jar du package
Fop-0.18.1-DEV.

En : Perhaps, this will help you.  I in entered chains xml and the path
of a file xsl, I produces initially an output fo, and then, starting from
this flow, I produces the output pdf which sets out again towards the
customer.  This this master key within the framework of a servlet. This
goes very well and uses xalan-2.0.0.jar, xerces-1.2.3.jar and fop.jar of
Fop-0.18.1-DEV package.

Code :
    // Production de la source d'entr�e XML
    javax.xml.transform.TransformerFactory tFactory =
javax.xml.transform.TransformerFactory.newInstance();
    StringReader sr = new StringReader (chaineXml);
    javax.xml.transform.Source xmlSource = new
javax.xml.transform.stream.StreamSource (sr);

    // Production de la source d'entr�e XSL
    javax.xml.transform.Source xslSource = new
javax.xml.transform.stream.StreamSource (new FileReader (xsltFile));
    javax.xml.transform.Transformer transformer = tFactory.newTransformer
(xslSource);

    // Production du flux fo
    StringWriter sw = new StringWriter ();
    transformer.transform (xmlSource, new
javax.xml.transform.stream.StreamResult (sw));
    StringReader fo = new StringReader (sw.toString());

    // Transformation du fo en pdf
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Driver pilote = new Driver (new InputSource(fo), out);
    pilote.setRenderer(Driver.RENDER_PDF);
    pilote.run();

    // R�cup�ration du flux de sorti pdf et envoi vers le client
    byte[] content = out.toByteArray();
    response.setContentLength(content.length);
    response.getOutputStream().write(content);
    response.getOutputStream().flush();


f0 fo a �crit :

> hi All!!
>    I'm trying to generate a PDF file from a xml & xsl
> file which will create a .fo file which is given to
> the buildFOTree() of the Driver class.
>   Now, I'm able to write to the fotree to a physical
> file, then create a PDF.(this works fine).
>  But I don't want to write the fo tree to a physical
> file & read using the SAXReader with the buidFOTree of
> the Driver , instead I want to read usind a Document
> object.
>   I tried getting the result from XSLProcessor into
> DOMResult object and tried getting the Document object
> by DOMResult foTree = DOMResult();
> XSLTProcessor processor = new XSLTProcessor();
> processsor.process(new XSLTSource("file1"),
>                    new XSLTSource("file2"),
>                    foTree);
> ...
> ...
> Driver driver = null;
> ...
> ...
> driver.buildFOTree(foTree.getNode().getOwnerDocument());
> ...
> ..
>
> This program throws me a
> java.lang.NoSuchMethodError: org.w3c.dom.Document:
> method createElementNS(Ljava/lang/String;Ljava/la
> ng/String;)Lorg/w3c/dom/Element; not found
>
> Hope the problem is clear.,.,,
> help is appreciated
> thanks,
> Kumar
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org