John,
Thank you for your message.
Yes, I realize the data in the byte array "bt" in tiff
does not belong to the standard formatting object.
That is why I got the error "content is not allowed in
prolog". My understanding is I need to either convert
it into the formatting object using XSL or convert it
into XML. However, I am new to FOP and XML/XSL and do
not know how to do that. If possible, we need to
convert the data format in memory,that means,
everything is done in memory, not save it as a file
first and process using FOP. Would you please give me
your thought on it or you have a piece of codes for me
to share? I will greatly appreciate it.
Thanks in advance,
Jerry
--- John Austin <[EMAIL PROTECTED]> wrote:
> On Thu, 2004-04-01 at 14:30, Jerry wrote:
> > Hi,
> >
> > I am currently working on a
> > project which convert binary data in tiff format
> into
> > PDF format. I refer to the
> example(FopServlet.java)
> > and always got error "Error 500: Content is
> > not allowed in prolog. ". I could not figure out
> what
> > the problem is. I was stuch by this. Please help
> me.
> >
> > Here is the peice of codes. Would you please take
> a
> > look and give me a suggestion. I will greatly
> > appreciate it.
> >
> > BTW, the binary data format from database which
> will
> > be displayed on the web is in tiff format, not a
> > formatting object. If it can be displayed directly
> on
> > the web in pdf format, it is not necessary to
> convert
> > it into pdf first.
>
> It is not clear from your example whether your data
> is usable by
> FOP.
>
> FOP is designed to process XML files, specifically
> XSL-FO or
> Formatting objects.
>
> You state on your message and in comments that the
> binary data is
> in a TIFF format. You move this data around,
> eventualy passing it
> to the FOP Driver object. I don't think this is at
> all reasonable
> as a TIFF object is definitely not going to be
> accepted by the SAX
> parser used in FOP.
>
> You need to read the FOP examples again.
>
> > thanks,
> >
> > Jerry
> >
> >
>
***********************************************************
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > import java.io.*;
> > import java.util.*;
> > import java.util.zip.*;
> > import java.sql.*;
> > import java.text.*;
> >
> >
> > import java.net.*;
> > import java.util.Properties;
> > import java.awt.image.*;
> > import com.sun.media.jai.codec.*;
> > import com.sun.media.jai.*;
> > import javax.media.jai.JAI;
> > import javax.media.jai.*;
> > import javax.media.jai.RenderedOp;
> > import javax.media.jai.PlanarImage;
> > import javax.media.jai.OpImage;
> > import javax.media.jai.util.*;
> > import
> > javax.media.jai.remote.SerializableRenderedImage;
> > import java.awt.image.renderable.ParameterBlock;
> > import java.lang.Object;
> > import java.awt.Image;
> > import javax.swing.ImageIcon;
> > import java.io.ByteArrayOutputStream.*;
> >
> >
> > import com.csi.utils.StringUtils;
> > import com.csi.daserver.global.*;
> > import com.csi.dcserver.objects.DCSession;
> > import com.csi.dcserver.exceptions.*;
> > import com.csi.daserver.utils.MsgPool;
> > import com.csi.dcserver.crypto.Crypto;
> >
> >
> > import org.xml.sax.InputSource;
> >
> > import org.apache.fop.apps.Driver;
> > import org.apache.fop.apps.XSLTInputHandler;
> > import org.apache.fop.messaging.MessageHandler;
> >
> > import
> > org.apache.avalon.framework.logger.ConsoleLogger;
> > import org.apache.avalon.framework.logger.Logger;
> >
> >
> > public class ImageDownload extends HttpServlet {
> >
> > Logger log = null;
> > ....
> > public void doGet(HttpServletRequest req,
> > HttpServletResponse resp) throws ServletException,
> > IOException {
> >
> > ...
> >
> > //got the binary data in tiff format from
> database
> > and put the binary data in byte array bt
> > Byte[] bt = (byte[]) v.elementAt(0);
> >
> > sendPDFBinaryResponse(resp, req, bt,
> > "application/pdf");
> > return;
> > }
> > }
> >
> > //
> > private void
> > sendPDFBinaryResponse(HttpServletResponse
> > res,HttpServletRequest req, byte[]
> > bt,StringsContTypeHeader) throws IOException,
> > ServletException{
> >
> >
> >
> > if(sContTypeHeader=="application/pdf"){
> >
> > if (log == null) {
> > log = new
> > ConsoleLogger(ConsoleLogger.LEVEL_WARN);
> > MessageHandler.setScreenLogger(log);
> > }
> >
> >
> > renderFO(new InputSource(new
> > ByteArrayInputStream(bt)), res);
> >
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > public void renderFO(InputSource foFile,
> > HttpServletResponse response) throws
> ServletException
> > {
> > try {
> > ByteArrayOutputStream out = new
> > ByteArrayOutputStream();
> >
> >
> > response.setContentType("application/pdf");
> >
> > Driver driver = new Driver(foFile,
> out);
> > driver.setLogger(log);
> > driver.setRenderer(Driver.RENDER_PDF);
>
> >
> > driver.run();
> >
> > byte[] content = out.toByteArray();
> >
> >
> >
> response.setContentLength(content.length);
> >
> response.getOutputStream().write(content);
> > response.getOutputStream().flush();
> >
> >
> >
> > } catch (Exception ex) {
> > throw new ServletException(ex);
> > }
> > }
> >
> > ...
> >
> > }
> >
> >
> > ****************
> > This is the exact error I got:
> >
> > org.xml.sax.SAXParseException: Content is not
> allowed
> > in prolog.
> > at
> >
>
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1172)
>
=== message truncated ===
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/