John and folks,
First of all, thank you for your help.
I am still struggling with my PDF conversion. I am a
little headache with this. We have a lot of FOP/JAXP
professional here and hopefully I can get your
suggestion.
>From what you suggested me, I read a lot of reference
and resources. Now I tryed to use JAXP and FOP to
convert the binary tiff data into PDF format and I
got an error "Error 500:java.io.ByteArrayInputStream".
I know something wrong with my code. I just couldn't
figure out how to fix it. Below is the partcial codes
I wrote. Can you please take a look at my code and
give me your recommandation? I know I already
bothered you too much. You are not supposed to spend
time on this for me. If you don't have time, I totally
understand that. If you could help me, I will greatly
appreciate it. I use * to mark the part which I have
problem with. I also enclosed my XSL file here for
your reference.
My servlet:
public class ImageDownload extends HttpServlet {
...
public void doPost(HttpServletRequest req,
HttpServletResponse resp) throws
ServletException, IOException {
...
//get binary tiff data from database and put it in
an byte array
byte[] bt=(byte[]) v.elementAt(0);
DisplayToPdf(bt, resp);
}
public void DisplayToPdf(byte[] bt,
HttpServletResponse response) throws ServletException
{
try {
ByteArrayOutputStream out = new
ByteArrayOutputStream();
response.setContentType("application/pdf");
Driver driver = new Driver();
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
ByteArrayInputStream bais=new
ByteArrayInputStream(bt);
File xslfile = new
File("C:/workspace/MaxTradDownload/Web
Content/html/Tiff2Pdf.xsl");
try {
driver.setOutputStream(out);
//Setup XSLT
TransformerFactory factory =
TransformerFactory.newInstance();
Transformer transformer =
factory.newTransformer(new StreamSource(xslfile));
//*assign ByteArrayInputStream bais to image
variable in xsltfile, seems like it is not working.
transformer.setParameter("image", bais);
//Setup input for XSLT transformation
//*Here, I need to do something to convert
ByteArrayInputStream into Source type. I haven't
figure out how to do or if it is possible
//Source src =
team.getSourceForProjectTeam();
//Resulting SAX events (the generated FO)
must be piped through to FOP
Result res = new
SAXResult(driver.getContentHandler());
//Start XSLT transformation and FOP
processing
//* I need to work on the first parameter
transformer.transform((Source)bais, res);
byte[] content = out.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
} finally {
out.close();
}
} catch (Exception ex) {
throw new ServletException(ex);
}
}
}
*********************
My XSL(Tiff2pdf.xsl) file for your reference:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<fo:root font-family="Times Roman" font-size="12pt"
text-align="center"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
margin-right="1.5cm"
margin-left="1.5cm"
margin-bottom="2cm"
margin-top="1cm"
page-width="21cm"
page-height="29.7cm"
master-name="left">
<fo:region-before extent="1cm"/>
<fo:region-body margin-top="1cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence id="N2528" master-reference="left">
<fo:static-content flow-name="xsl-region-after">
<fo:block text-align-last="center" font-size="10pt">
<fo:page-number/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="18pt" font-weight="bold">Copy
Only</fo:block>
<fo:block>
<fo:block font-size="16pt" font-weight="bold"
space-before.minimum="1em"
space-before.optimum="1.5em"
space-before.maximum="2em">Align in Smaller
Viewport</fo:block>
<fo:block>
<!-- <fo:external-graphic width="50pt" height="50pt"
overflow="hidden"
src="C:/TifDownloadData/20040326110116.tiff"/>-->
<fo:external-graphic width="50pt" height="50pt"
overflow="hidden" src="[EMAIL PROTECTED]"/>
</fo:block>
<fo:block font-size="16pt" font-weight="bold"
space-before.minimum="1em"
space-before.optimum="1.5em"
space-before.maximum="2em"/>
This document is just Copy only, Non Negotiable
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:stylesheet>
--- John Austin <[EMAIL PROTECTED]> wrote:
> You asked this question on the devl list and Chris
> gave you an excellent
> answer.
>
> He also suggested that you read up a bit on XSL-FO
> as there are standard
> techniques that can be used to embed TIFF images in
> XSL-FO documents.
>
> Several people spent a bit of time reading your
> servlet. Please re-read
> Chris' answer to you and look for an example XSL-FO
> document that embeds
> a TIFF graphic. You should be able to find XSL-FO
> resources on the web.
> Look for the web version of Dave Pawson's book. Look
> for the Mulberry
> resources and the OASIS web site. Search the
> FOP-USER archives as well
> as the Mulberry XSL list archive.
>
> I don't think you need a servlet yet. The first
> thing you need is
> an XSL-FO example of a document that embeds a TIFF
> document.
> You may need to understand XSL-FO better to do this.
>
> You can render this in PDF, PCL, etc using FOP from
> the command line.
>
> Your next step would be to generate the TIFF file
> from the database
> as Chris suggested. This could be done with a CGI or
> Servlet.
>
> You'll get a lot of help here as long as people can
> see that you've
> made some effort on your own.
>
> On Fri, 2004-04-02 at 14:27, Jerry wrote:
> > Hi,
> >
> > I have a problem with displaying tiff data in PDF
> > format using FOP. We have binary data in tiff
> stored
> > in database. What I need to do is to write a
> servlet
> > to get those binary data in tiff format from
> database
> > and put those data in a byte array. Next, in the
> same
> > servlet, I need to get those binary data in tiff
> > format from the byte array and display them on the
> web
> > in PDF format using FOP. I know if the binary data
> is
> > formatted object, it is easy to convert it into
> PDF
> > using FOP. However, the data in the byte array
> "bt" in
> > tiff does not belong to the standard formatting
> > object.
> > 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. Anyone has the
> > experience and would like to share the knowledge
> and
> > experience with me, I will greatly appreciate. If
> you
> > have a piece of codes for me to share, that will
> be
> > greatly helpful.
> >
> > I also attached my piece of codes for your
> reference.
> > I know my code is not working, because I tried to
> > convert non-standard formatting object to PDF. I
> need
> > to do something about this part. Please help me.
> >
> > Thanks in advance,
> >
> >
> > 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();
> >
>
=== message truncated ===
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]