Hi,

I am trying to generate pdf using servlet.

I am getting junk in the browser:
"%PDF-1.4 %���� 2 0 obj <> stream [EMAIL PROTECTED])�� ... "

When I write the output to a file by using the same code, It is working.

Here is the code servlet version code: Can you please help me with this code.

package com.iamnpf.penapp;

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

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

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

public class PANotMarriedStatement extends HttpServlet {


  public void doGet (HttpServletRequest request,
                     HttpServletResponse response)
       throws ServletException, IOException
  {

    String applicant = "John Doe";
    String string1 = ", text here text here text here.";

    Paragraph para1 = new Paragraph("Statement by Applicant Who is Not Married\n");
    Paragraph para6 = new Paragraph("Date      (Attach Death Certificate)");
    Paragraph para7 = new Paragraph("");
    Paragraph para9 = new Paragraph("text.");
    Paragraph para10 = new Paragraph("Applicant's signature_");
    Paragraph para11 = new Paragraph("Notary's Certification");
    Paragraph para12 = new Paragraph("State of");
    Paragraph para13 = new Paragraph("I certify that");

    Chunk chunk8 = new Chunk(string1);

    para7.add(chunk8);

    para1.setAlignment(1);

    para6.setIndentationLeft(200);
    para7.setIndentationLeft(50);


    para6.setLeading(10);

        try {
            Document document = new Document();
             response.setContentType("application/pdf");
             response.setHeader("Expires", "0");
             response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
             response.setHeader("Pragma", "public");

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            //PdfWriter.getInstance(document, new FileOutputStream("c:\\temp\\PANotMarriedStatement.pdf"));
            document.open();

            document.add(para1);
            document.add(new Paragraph("\n"));
            document.add(para6);
            document.add(new Paragraph("\n"));
            document.add(para7);
            document.add(new Paragraph("\n"));
            document.add(para9);
            document.add(new Paragraph("\n"));
            document.add(para10);
            document.add(new Paragraph("\n"));
            document.add(para11);
            document.add(new Paragraph("\n"));
            document.add(para12);
            document.add(new Paragraph("\n"));
            document.add(para13);

            document.close();
            response.setContentLength(baos.size());
            response.setBufferSize(baos.size());
            ServletOutputStream out = response.getOutputStream();
            baos.writeTo(out);
            out.flush();
        }
        catch(DocumentException de) {
          de.printStackTrace();
          System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
          ioe.printStackTrace();
          System.err.println(ioe.getMessage());
        }

    }
}



It's new, it's here! It's full of fun! MSN Messenger V6.0 ------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to