You need to set the content-length and content-type on the response.

response.setContentType("application/pdf");
response.setContentLength(baos.size());

those methods might be a little different, but you get the point

Bill

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of gs lai
Sent: Sunday, April 11, 2004 7:53 PM
To: [EMAIL PROTECTED]
Subject: [iText-questions] why PdfStamper can write to FileOutputStream
but not to ServletOutputStream


I want to read a file and change something,then to the browser and I see
nothing,but to a file which is i want,Can you tell where is my wrong(with
j2sdk1.4.1_03,tomcat4.1.24,iText1.02b,MS ie6.0sp1).thanks for your doing for
us,and your help
the code is:

public class PrintProtocolUsePdfAction
    extends org.apache.struts.action.Action {
    public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response) throws
Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        response.setHeader("Cache-Control", "max-age=30");
        response.setHeader("Content-Type", "application/pdf");
        PdfReader reader = new PdfReader("D:\\Tomcat
4.1\\webapps\\tms\\docs\\protocol1.pdf");
        PdfStamper stamp = new PdfStamper(reader,new
FileOutputStream("D:\\Tomcat 4.1\\webapps\\tms\\docs\\obj.pdf"));//(1)
//      PdfStamper stamp = new PdfStamper(reader,baos);//(2)
        AcroFields aform = stamp.getAcroFields();
        aform.setField("text1", "hello,iText");
        stamp.setFormFlattening(true);
        ServletOutputStream out= response.getOutputStream();
        baos.flush();
        baos.writeTo(out);
        stamp.close();
        out.flush();
        baos.reset();
        return null
    }
}

notes:
(1)write to file,and it is ok!
(2)write to browser,then it doesn't work.why?
thanks again.

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to