Hi
I am trying to generate PDF from servelet.I tried with
JSP but could not able to succedd.Now i am trying with
servlet its not giving any exceptions but pdf report is not getting disdplayed and my browser window is getting hanged.
Can some body help me pleae..
Here is my code
import java.io.PrintWriter;
import java.io.IOException;
import java.io.File;
import java.util.Date;
import javax.servlet.http.*;
import javax.servlet.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.html.HtmlWriter;
public class Chap0105 extends HttpServlet {
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// we retrieve the presentationtype
String presentationtype = "pdf";
// step 1
System.out.println("---inside servelit----");
Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
try {
// step 2: we set the ContentType and create an instance of the corresponding Writer
if ("pdf".equals(presentationtype)) {
response.setContentType("application/pdf");
PdfWriter.getInstance(document, response.getOutputStream());
}
else if ("html".equals(presentationtype)) {
response.setContentType("text/html");
HtmlWriter.getInstance(document, response.getOutputStream());
}
else {
response.sendRedirect("http://www.lowagie.com/iText/tutorial/ch01.html#step2");
}
// step 3
document.open();
// step 4
document.add(new Paragraph(new Date().toString()));
}
catch(DocumentException de) {
de.printStackTrace();
System.err.println("document: " + de.getMessage());
}
// step 5: we close the document (the outputstream is also closed internally)
document.close();
}
}
Regards
Radha