I am developing a web application using JSP, servlet in ubuntu. I want to convert a JSP page into PDF. I dont want to store the PDF file in my local drive. Just convert into PDF and view Dynamically while i click a Button.

For Example,

In "index.jsp", i hava 2 Text boxes, one is for from date and another one is for to date. I have one submit button "Generate PDF Report". If i click that button, it will redirect to "report.jsp". In that page, I using the follwing code,

            <td>Roll No</td>
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery("select * from testtable where fromdate='"+requset.getParameter("fdate")+"' and todate='"+requset.getParameter("tdate")+"'");

Then the output will be displayed in a PDF page like this,

             Roll No                     Name
                1                       XXXX
                2                       YYYY
                3                       ZZZZ

Any one can help Please....?

hi rajilakshmi,
to generate a pdf report we have jar file called iText.jar,
Itext is a frame work which helps to mainipulate pdf files,
take a look on the following example

try {
            Document document=new Document();
            PdfWriter.getInstance(document,new FileOutputStream("D:\\myfile.pdf"));
            document.add(new Paragraph("This is my file"));
        } catch (Exception e) {

before that dont forget to include the itext.jar

I already used iText.jar and iTextPDF.jar files. I dont want to store that file in local disk. I just convert the JSP to PDF dynamically. Because i am using this for report generation in my application. I already done this in PHP. But i dont know how to convert in java. I tried the below code

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

import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;

import java.io.*;
import java.util.*;

public class pdffile extends HttpServlet 

    public void init(ServletConfig config) throws ServletException

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

    public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
        response.setContentType("application/pdf"); // Code 1

        Document document = new Document();
            response.getOutputStream()); // Code 2
            // Code 3
            PdfPTable table = new PdfPTable(2);
            // Code 4
                catch(DocumentException e)
                    //out.println("Exception: "+e);


The above code it just convert this static page into PDF. I want to convert the dynamic page into PDF format. For example i want to create a table that retrives the data from database and if the user clicks the "Generate Report" button, it will directly redirect to that PDF table page.
Anyone can help please....?

hi, did u manage to find out the solution ? i m facing the same problem.

you could've created your own thread in which you ask for this, especially while showing your code.
but since this is about jsp, you might as well post it in the jsp sub-forum.


Is the solution found, I'm facing the same issue.