[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Question regarding use of FOP
- From: Gael G De Barbeyrac <debarbeyrac_gael@jpmorgan.com>
- To: noble.dzakpasu@commerceone.com
- Date: Wed, 07 Feb 2001 18:40:25 +0100
Sorry, I was busy all day. Here is a copy of a recent mail I sent over to
someone else. It may help. If this is still not ok, shout for help.
----------------------------------------------------------- mail sent to
marc.mueller@danet.de
-------------------------------------------------------------
Hi, I will try to answer shortly:
- I have built an engine that transforms XML documents into intermediary FOP
documents that are then rendered into PDF. This engine is interfaced via
Servlets. PDF Docs are returned as HTTP response (content type:
application/pdf).
- I have been using version 0.14 of FOP toolbox along with xalan J20D01 (for
XLST processing) and xerces 1.1.3 (for XML Parsing with SAX V2). You could try
to use Cocoon instead. However, I haven't tried it yet.
- The following code extracts show you how the PDF document is produced. It is
fairly simple.
- you should pay attention to the CLASSPATH. Apparently there are DOM conflicts
between versions of xalan, xerces, and FOP (keep this order).
Import statements:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
// SAX
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
// Java
import java.io.FileReader;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.URL;
// FOP
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.apps.*;
//import org.apache.xpath.xml.FormatterToXML;
import org.w3c.dom.Document;
Method used to generate PDF document (out) from FOP formated document (in):
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);
// Don't know why its required.
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);
debuglog("FO Tree Built - now formatting");
driver.format();
driver.render();
// That's it.
}
noble.dzakpasu@commerceone.com on 02/07/2001 06:06:43 PM
To: noble.dzakpasu@commerceone.com, debarbeyrac_gael@jpmorgan.com
cc: jin.ren@commerceone.com
Subject: RE: Question regarding use of FOP
I forgot to cc my team mate. Please reply to all.
Many Thanks.
Noble
-----Original Message-----
From: Dzakpasu, Noble
To: 'debarbeyrac_gael@jpmorgan.com'
Cc: Dzakpasu, Noble
Sent: 2/7/01 12:04 PM
Subject: Question regarding use of FOP
Hi,
We are working on an application that must translate reports in pdf
format. We discovered your response to a related issue on the web and
are curious about the createParser() method call. Our JSP file fails
on the line. Which library do we need to import to obtain the XMLReader
functionality.
Any help will be greatly appreciated.
Noble.
===============
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();
}
This communication is for informational purposes only. It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan Chase & Co. Incorporated, its
subsidiaries and affiliates.