OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: XML TO PDF

[ Lists Home | Date Index | Thread Index ]
  • From: Geeta Gudavalli <ggudavalli@McLeodUSA.com>
  • To: xml-dev@lists.xml.org
  • Date: Tue, 12 Dec 2000 11:53:05 -0600



Hello,
     I tried this approcah but does not work.  I am sending piece of coe below.
Any help is grealty appreciated.  I can create the pdf document but does not
write the document in the browser.

  res.setContentType ("application/pdf");
          PrintWriter stds = new PrintWriter(res.getOutputStream());

          driver.setWriter(stds);
          System.out.println("fop step 5");

          driver.buildFOTree((Parser)parser, new InputSource("test.fo") );
          System.out.println("fop step 6");

          driver.format();
          System.out.println("fop step 7");

          driver.render();
          System.out.println("done fop ");

          stds.flush();

Thank you,
Geeta
---------------------- Forwarded by Geeta Gudavalli/MCLEOD on 12/12/2000 11:55
AM ---------------------------


Gael G De Barbeyrac <debarbeyrac_gael@jpmorgan.com> on 12/11/2000 03:14:44 AM

To:   Geeta Gudavalli/MCLEOD@MCLEOD
cc:   xml-dev@lists.xml.org
Subject:  Re: XML TO PDF



Hi,

I am still not sure what our problem is, however, I am sending you a piece of
code to explain the kind of solution I see:

In the following extract, I am showing a the unique and fairly simple method
that I am using to generate the PDF without having to rely on any file.

protected void buildPDFDoc(InputSource in, PrintWriter out) throws Exception {
    String version = org.apache.fop.apps.Version.getVersion() ;


    XMLReader parser = createParser();
    parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();
    driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version);
    driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
    driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
    driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
    driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
    driver.setWriter(out);
    driver.buildFOTree(parser, in);
    driver.format();
    driver.render();
  }

As you see there are only two parameters:

- in parameter is a wrapper around any byte stream (not only files).

      I am initializing this parameter from a string that contains the XSL
rendering instructions (fo:root, fo:....) built from the initial XML file
transformed via an XSLT file.

      Reader reader = new java.io.StringReader(docstring);
      InputSource foDoc = new InputSource(reader);

- the out parameter is a wrapper around any output byte stream. The very same
hypothesis applies here again:
I initializing it with the HttpResponse.getWriter() method which, as you may
know, allows writting to the output.

Before starting to write to the output, you must position the mime type of the
document to tell the browser that it needs to use acrobat reader to open the
document sent in the response stream.

    PrintWriter stdout = response.getWriter();
    response.setContentType("application/pdf");

Thus I do not need any temporary file to produce PDF documents directly from XSL
 documents. This method works just fine for medium sized documents (hundreds of
kilobytes).
But, I haven't tested it in case the document to render is giant in size (memory
 consumption problems may appear).

Hoping that this input will be helpfull you.

Gael.





ggudavalli@mcleodusa.com on 12/09/2000 01:07:56 AM

To:   xml-dev@lists.xml.org
cc:   (bcc: Gael G De Barbeyrac)
Subject:  Re: XML TO PDF






Hello,
     I am successful in creating pdf document from xml and xsl file using
servlet running Apache jserv.  My problem is sending the pdf file as output i.e
to open the pdf file in my servlet.  I am getting socketexception but I am not
opening any sockets.  Your help is greatly appreciated.
Thank you,
Geeta
---------------------- Forwarded by Geeta Gudavalli/MCLEOD on 12/08/2000 06:09
PM ---------------------------


Gael G De Barbeyrac <debarbeyrac_gael@jpmorgan.com> on 12/01/2000 11:29:54 AM

To:   Geeta Gudavalli/MCLEOD@MCLEOD
cc:   xml-dev@lists.xml.org
Subject:  Re: XML TO PDF



I am using a servlet running under Apache/JServ 1.1.1 (a bit oldie, but it is
ok) with Xalan / FOP to the which I pass parameters to select the xsl file that
contains the FOP transformation rules to apply the xml file to transform (could
be built from a database extract). Then I use the PDF rendering mechanism of FOP
and output the PDF byte code to the HTTP response with the mime type
application/pdf. And that works just fine.

I am sure you could apply this strategy into any servlet environment without
having to rely on apache / cocoon.





ggudavalli@mcleodusa.com on 12/01/2000 05:46:22 PM

To:   xml-dev@lists.xml.org
cc:   (bcc: Gael G De Barbeyrac)
Subject:  XML TO PDF






I have two questions regarding transforming XML to PDF.
1.  I get data from db2 as xml format.  This file has different templates in it.
When I transform this to pdf, I am getting error at FOP rendering because the
xsl file does not just choose the template I specify.  It picks up all the data
from the file.  This causes fop to error out.  The e sample xml file is given
below.  Can someone help me figure out how to select only one template at a time
with out parsing the xml file to break it into different files.

(See attached file: out.xml)(See attached file: obf_dl_form.xsl)  In the xls
file, I need to select only "DL" but it brings the values of fields from DSR and
SA also.


2.  How can I run XALAN and FOP interactively from a web page rather than a
batch process?  I do not want to use cocoon?  Is there another way?  I am
thinking of using Class and method.invoke to invoke the commands.

Your help is greatly appreciated.
Thank you,
Geeta




out.xml

obf_dl_form.xsl





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS