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;
>
> }
>
>
>
> -------------------------------------------------------
> 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