I ran into some other odd problems opening documents so I also added in
addition to those below to correct them:
response.setHeader("Pragma", "public");
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Woodchuck
Sent: Thursday, June 03, 2004 1:21 PM
To: itext
Subject: Re: [iText-questions] Struts Framework and iText
Hi Michael,
Thanks for your reply. My original code was correct,
and it was basically the same as yours in terms of the
steps. I think the important steps are
setContentType(), and setContentLength().
I was getting a blank page because of my IE version
(6.0.2800.1106), it requires me to add the following
to see the pdf:
response.setHeader("Cache-Control", "must-revalidate,
post-check=0, pre-check=0");
after hours of tweaking and trial and error I stumbled
on the workaround by accident.
--- Michael K <[EMAIL PROTECTED]> wrote:
> Hi,
>
> that works for me:
>
> ... building PDF ...
> then finish it
> // add a page break
> document.newPage();
>
> // step 5: we close the document (the
> outputstream is also
> closed
> // internally)
> document.close();
> // we have written the pdfstream to a
> ByteArrayOutputStream,
> // now we are going to write this
> outputStream to the
> // ServletOutputStream
> // after we have set the contentlength
>
> response.setContentType("application/pdf");
>
>
response.setHeader("Content-Disposition","attachment;filename=fileName.pdf")
> ;
> response.setContentLength(baos.size());
> ServletOutputStream out =
> response.getOutputStream();
> baos.writeTo(out);
> out.flush();
> ... catch block ...
>
> then
> return null; // in ActionForward execute()
>
> Best Regards.
> Michael.
>
>
> ----- Original Message -----
> From: "Woodchuck" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, June 02, 2004 10:55 AM
> Subject: [iText-questions] Struts Framework and
> iText
>
>
> > Hello,
> >
> > I have tried many times tweaking different things
> but I keep getting a
> blank
> > page instead of the PDF file.
> >
> > Does anyone know how to get iText working within
> the Struts framework? In
> my
> > Action class execute() function I do this:
> >
> > - create the PDF file as a ByteArrayOutputStream
> > - flush this to the ServletOutputStream
> > - return null
> >
> > I know the PDF file is created correctly because
> when I swap a
> FileOutputStream
> > object for the ByteArrayOutputStream object, the
> PDF is physically created
> > locally on my hard drive.
> >
> > I don't know what I'm doing wrong but here's my
> execute() function:
> >
> > public ActionForward execute(
> > ActionMapping mapping,
> > ActionForm form,
> > HttpServletRequest request,
> > HttpServletResponse response)
> > throws Exception
> > {
> > Document myDoc = new
> Document(PageSize.LETTER.rotate(), 0, 0, 0, 0);
> > ByteArrayOutputStream pdfStream = new
> ByteArrayOutputStream();
> > PdfWriter writer = null;
> >
> > try {
> >
> >
> > //writer =
> PdfWriter.getInstance(myDoc, new FileOutputStream
> > ("MYTEST.pdf"));
> > writer = PdfWriter.getInstance(myDoc,
> pdfStream);
> >
> > myDoc.addTitle("My PDF Test");
> > myDoc.addSubject("My PDF Subject");
> >
> > myDoc.open();
> >
> > Paragraph paragraph = new Paragraph();
> >
> paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
> > for (int i = 0; i < 20; i++) {
> > paragraph.add("TESTING PDF FILE
> BODY TEXT TESTING PDF FILE
> BODY
> > TEXT TESTING PDF FILE BODY TEXT TESTING PDF FILE
> BODY TEXT");
> > }
> > myDoc.add(paragraph);
> >
> > myDoc.close();
> >
> >
> response.setContentType("application/pdf");
> >
> >
> response.setContentLength(pdfStream.size());
> >
> > ServletOutputStream sos;
> >
> > sos = response.getOutputStream();
> >
> > sos.write(pdfStream.toByteArray());
> > //pdfStream.writeTo(sos);
> >
> >
> > sos.flush();
> >
> > } catch (DocumentException de){}
> > catch (IOException io){}
> >
> > return null;
> >
> > }
> >
> >
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions
-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions