<html>
<head>
<meta name="GENERATOR" content="Namo WebEditor">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/main_style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

</head>
<body>
<center>

<tr> <th style='width: 3%;'> S.NO </th>

       <th style='width: 6%;'> Company ID </th>


   <th style='width: 10%;' > Company Name </th>
   <th style='width: 6%;' > More Company Details </th>
   <th style='width: 6%;'> User Details </th>
   <th style='width: 6%;'> Submission Summary </th>

</tr>

<%
ArrayList<BasicInfoJB> list=(ArrayList<BasicInfoJB>)session.getAttribute("companyBasicInfo");
%>

<%

    int i;
  for(i=0;i<list.size();i++){       


     BasicInfoJB bJB=(BasicInfoJB)list.get(i);    
out.println("<tr>");

    out.println("<td align='center'>"  );
    out.print(i+1);
    out.println("</td> ");

    out.println("<td>");
    out.print(bJB.getCOMPANY_ID());
    out.println("</td>");

    out.println("<td>");
    out.print(bJB.getCOMPANY_NAME());
    out.println("</td>");

    out.println("<td align='center'>");
    out.print("<a href='cmpnymrinfo?cid="+bJB.getCOMPANY_ID()+"'>ClickHere</a>");
    out.println("</td>");

    out.println("<td align='center'>");
    out.print("<a href='userdetails?cid="+bJB.getCOMPANY_ID()+"'>ClickHere</a>");
    out.println("</td>");

    out.println("<td align='center'>");
    out.print("<a href='submissumary?cid="+bJB.getCOMPANY_ID()+"'>ClickHere</a>");
    out.println("</td>");

out.println("</tr>");
    }

   %> 

</table>

<%out.println("<h2 style=\"color:red;font-family:verdana\"> Number of companies: "+i+"</h2>"); %>

</body>
</html>

Dani AI

Generated

As suggested, treat PDF generation as a server-side task: move the data/logic out of the JSP into a servlet or controller and stream a PDF back to the browser instead of trying to convert the JSP text directly. Using iText 7 you can build the PDF programmatically and write it straight to the servlet output stream (no temporary file required). This keeps the JSP as the HTML view and the servlet responsible for producing a proper PDF. (kb.itextpdf.com)

Example (minimal servlet sketch using iText 7 — adapt your loop that reads the company list to populate the document):

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/pdf");
    resp.setHeader("Content-Disposition", "attachment; filename=\"companies.pdf\"");
    try (ServletOutputStream os = resp.getOutputStream()) {
        PdfWriter writer = new PdfWriter(os);
        PdfDocument pdf = new PdfDocument(writer);
        Document doc = new Document(pdf);
        // build a Table or Paragraphs here from your session/model data
        doc.add(new Paragraph("Company list"));
        doc.close();
    }
}

This pattern uses PdfWriter with an OutputStream so the PDF streams to the client; the iText docs show this basic flow and HTML-to-PDF helpers (see next note). (kb.itextpdf.com)

If you need the JSP's exact layout/CSS preserved, converting HTML to PDF is a different problem: iText offers the pdfHTML add-on (dual‑licensed AGPL/commercial), while open-source options include OpenHTMLToPDF (Flying Saucer + PDFBox) or using Apache PDFBox for programmatic PDFs. Check licensing before choosing pdfHTML for a web app. Quick troubleshooting: do not call getWriter() and getOutputStream() together, buffer to ByteArrayOutputStream if you need Content-Length, and embed fonts for non‑Latin text. (github.com)

I would recommend first learning to use servlets.
in the end, you won't be "turning your jsp in a pdf", you'll just write the information that is displayed in your jsp to a pdf file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.