Thanks Sean,

I tried modifying the code per the example http://www.pjug.org/PDFServlet.java. Still No Luck.

Here is the code I have right now.

=====

package com.iamnpf.penapp;

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ByteArrayOutputStream;

import javax.servlet.*;
import javax.servlet.http.*;

import com.iamnpf.global.*;
import atg.servlet.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class PAParticipantStatement extends DynamoServlet {

  public PAParticipantStatement() {}

  public void service (DynamoHttpServletRequest request,
                       DynamoHttpServletResponse response)
       throws ServletException, IOException
  {

    final String strFilename = "PAParticipantStatement_" + System.currentTimeMillis() + ".pdf";
    String strContentDispValue = "inline; filename="  + strFilename;

    DocumentException ex = null;

    ByteArrayOutputStream baosPDF = null;

    try {


      baosPDF = generatePDFDocumentBytes();

      response.setHeader("Cache-control", "must-revalidate");
      response.setHeader("Content-disposition",strContentDispValue);
      response.setContentType("application/pdf");

      byte[] yaPDFDocument = baosPDF.toByteArray();

      response.setContentLength(yaPDFDocument.length);

      ServletOutputStream sos = null;

      sos = response.getOutputStream();
      sos.write(yaPDFDocument);
      sos.flush();

    }
    catch(DocumentException de) {
          de.printStackTrace();
    }
    catch(IOException ioe) {
          ioe.printStackTrace();
    }
  }

  protected ByteArrayOutputStream generatePDFDocumentBytes()
    throws DocumentException

  {


    Font myFont1 = FontFactory.getFont(FontFactory.HELVETICA, 11, Font.NORMAL,new Color(0,0,0));
    String string1 = "Participant's Statement";
    String string2 = "Please read this statement carefully before signing.";

    Chunk chunk1 = new Chunk(string1,myFont1);
    Chunk chunk2 = new Chunk(string2,myFont1);

    Paragraph para1 = new Paragraph(chunk1);
    Paragraph para2 = new Paragraph(chunk2);

    para1.setAlignment(1);
    Document document = new Document();

    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter docWriter = null;

    try
    {
      docWriter = PdfWriter.getInstance(document, baosPDF);
      document.setPageSize(PageSize.A4);

      document.open();

      document.add(para1);
      document.add(new Paragraph("\n"));
      document.add(para2);
      document.add(new Paragraph("\n"));
      document.close();

    }
    catch (DocumentException dex)
    {
      baosPDF.reset();
      throw dex;
    }
    finally
    {
      if (document != null)
      {
        document.close();
      }
      if (docWriter != null)
      {
        docWriter.close();
      }
    }

    if (baosPDF.size() < 1)
    {
      throw new DocumentException(
        "document has "
        + baosPDF.size()
        + " bytes");
    }
    return baosPDF;
  }

}

=====

Regards,

Ishaq.

----Original Message Follows----
From: "Sullivan, Sean C - MWT" <[EMAIL PROTECTED]>
To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
Subject: [iText-questions] RE: iText-questions digest, Vol 1 #1230 - 8 msgs
Date: Thu, 29 May 2003 14:10:22 -0700
1) it is advisable to invoke "setContentType" on
the HttpServletResponse object
2) it is advisable to set the Content-disposition header
as well
Example code is online @ http://www.pjug.org/PDFServlet.java
-Sean
> From: "Ishaq Ali Mohammed" <[EMAIL PROTECTED]>
>
> I am trying to generate PDF dynamically and I am using the work around
> suggested for IE i.e. write everything to ByteArrayOutputStream and set
> the content length etc. as explained in couple of examples.
>
> When I get to the page where I am supposed to see this PDF I get some
> garbage something linke this.
>
> [...]
>
>
-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions


Attention NRIs! Send money to India. Do it in a jiffy! ------------------------------------------------------- This SF.net email is sponsored by: eBay Get office equipment for less on eBay! http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to