Björn

could you take a look at the following tag definition to see if you see
something why it would not work
I implemented your change as well and it still does not work

Thanks
Martin

import java.io.*;

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

import javax.servlet.*;

import javax.servlet.http.*;

import org.apache.xalan.xslt.*;

import org.apache.fop.apps.*;

public class FO2PDFTag extends BodyTagSupport {

/**

* If no fo attribute is specified, the body contains the

* fo XML. Store it here.

*/

private String body = null;



/**

* The fo attribute is the resource to where the

* fo XML is, if it's not in the body.

*/

private String fo = null;

public String getFo() {

return (this.fo);

}

public void setFo(String fo) {

this.fo = fo;

}



/**

* Evaluate the body of the tag only if no fo attribute

* is specified.

*/

public int doStartTag() throws JspException {

if (fo == null) {

return (EVAL_BODY_AGAIN);

} else {

return (SKIP_BODY);

}

}



/**

* Save the body content in the body private variable.

*/

public int doAfterBody() throws JspException {

if (bodyContent == null) {

body = "";

} else {

body = bodyContent.getString().trim();

}

return (SKIP_BODY);

}



/**

* Render the PDF using FOP. This is where all the

* work of the tag takes place.

*/

public int doEndTag() throws JspException {


// Make an XSLTInputSource from either the body or the fo attribute

XSLTInputSource data;

HttpServletResponse resp;

if (body != null) {

data = new XSLTInputSource(new StringReader(body));

} else {

data = new
XSLTInputSource(pageContext.getServletContext().getResourceAsStream(fo));

}


try {

Driver driver = new Driver();

driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",

Version.getVersion());

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.buildFOTree(new org.apache.xerces.parsers.SAXParser(), new
XSLTInputSource(data));

driver.format();

// create a ByteArrayOutputStream to store the PDF data in

ByteArrayOutputStream ostr = new ByteArrayOutputStream();

driver.setOutputStream(ostr);

// render the PDF to the ByteArrayOutputStream

driver.render();

byte[] content = ostr.toByteArray();

resp = (HttpServletResponse)pageContext.getResponse();

resp.setContentType("application/pdf");

resp.setContentLength(content.length);

resp.setHeader("Content-Disposition", "inline;filename=xxx.pdf; ");


// print the PDF bytes in the ByteArrayOutputStream to the JspWriter.

pageContext.getOut().print(ostr);

} catch (Exception e) {

throw new JspException(e.toString());

}

return (EVAL_PAGE);

}



/**

* Release any allocated resources.

*/

public void release() {

this.body = null;

this.fo = null;

}

}

----- Original Message -----
From: "Moritz Björn-Hendrik, HH" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Tuesday, May 21, 2002 09:10 AM
Subject: AW: problem diplaying on the fly generated PDF files within IE


> We found out that we had to do the following:
>
> response.setContentType("application/pdf"); (as you are doing)
> response.setHeader("Content-Disposition", "inline;filename=xxx.pdf; ");
(IE
> seems to need this)
> response.setContentLength(pdf.length); (where pdf is the byte-Array
> containing the pdf-file)
>
> Björn
>
> > -----Ursprüngliche Nachricht-----
> > Von: Martin Kuypers [SMTP:[EMAIL PROTECTED]]
> > Gesendet am: Montag, 20. Mai 2002 13:29
> > An: Struts Users Mailing List
> > Betreff: Re: problem diplaying on the fly generated PDF files within
> > IE
> >
> > I have the following problem
> >
> > I generate PDF files on the fly using XSL FO togehter with a Taglibrary
> > When i generate the PDF it shows up just fine within Netscape and within
> > IE6.0 it shows it in an ascii form instead of Launching Acrobat Reader
> >
> > Acrobat Reader is installed correctly and it shows not dynamically
> > generated
> > PDF filesnicely within IE6.0
> > I read that i had to fake IE with adding ?fakeIE=test.pdf at the end of
> > the
> > call, but this doesn't seem to work eather
> >
> > I included a file as a little example
> >
> > The call looks like fo_2_pdf1.jsp?fakeIE=test.pdf
> >
> > Any suggestions would help
> >
> > Thanks
> > Martin Kuypers
> >
> > <%@taglib uri="/WEB-INF/fop.tld" prefix="fop" %>
> >
> > <%response.setContentType("application/pdf");%>
> >
> > <%String foFile = request.getParameter("fo");%>
> >
> > <fop:fo2pdf>
> >
> > <?xml version="1.0"?>
> >
> > <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
> >
> > <fo:layout-master-set>
> >
> > <fo:simple-page-master master-name="simple"
> >
> > page-height="11in"
> >
> > page-width="8.5in"
> >
> > margin-top="1in"
> >
> > margin-bottom="1in"
> >
> > margin-left="1in"
> >
> > margin-right="1in">
> >
> > <fo:region-body/>
> >
> > </fo:simple-page-master>
> >
> > </fo:layout-master-set>
> >
> >
> > <fo:page-sequence master-name="simple">
> >
> > <fo:flow flow-name="xsl-region-body" text-align="center">
> >
> > <fo:block font-size="24pt">
> >
> > Welcome to XSL FO!
> >
> > </fo:block>
> >
> > <fo:block font-size="18pt" color="blue">
> >
> > Welcome, Welcome, Welcome
> >
> > </fo:block>
> >
> > </fo:flow>
> >
> > </fo:page-sequence>
> >
> > </fo:root>
> >
> > </fop:fo2pdf>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to