Note that there are some explanatory texts on larger screens.

plurals
  1. POPDF Generator using iText and java
    primarykey
    data
    text
    <p>I need to generate a PDF using iText, also using ajax to it. I have given a button, when on click, I have to get a pop-up for saving a pdf file as generally we get in many of the downloadable files. I;m not finding any wrong in the code please look into the code and help me. I have to print a simple table with rows and columns which i'm not able to.</p> <p><strong>Ajax coding:</strong></p> <pre><code>function getFocusedPDF(){ alert("Inside create PDF ajax"); $.ajax({ url : '/PreTestWeb/getFocusedPDF', type : 'get', dataType : 'json', contentType : 'application/json', success : function(map) { console.log(map); }, error : function(map) { alert(map); alert("error occured!!!"); }, }); } </code></pre> <p><strong>Home Controller:</strong></p> <pre><code>@RequestMapping(value = "/getFocusedPDF", method = RequestMethod.GET) public void getRecentFocusGrpData(HttpServletRequest req, HttpServletResponse res) throws IOException, DocumentException { String contType="application/pdf"; res.setContentType(contType); Gson json = new Gson(); System.out.println("Inside home ctrlr"); PdfGenerator pdf=new PdfGenerator(); System.out.println("==== Before ==="); byte[] b=pdf.createFirstTable(); System.out.println("==== After ==="); res.setHeader("Content-Disposition", "attachment; filename=pdf.pdf"); res.setContentLength(b.length); res.getOutputStream().write(b); res.getOutputStream().flush(); res.getOutputStream().close(); System.out.println("Last line in home ctrlr pdf generation"); } </code></pre> <p><strong>createFirstTable: (Method)</strong></p> <pre><code>public static byte[] createFirstTable() throws DocumentException, FileNotFoundException { System.out.println("=========Inside pdf generator =========="); // a table with three columns ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); Document document=new Document(); PdfWriter writer = PdfWriter.getInstance(document, outputStream); writer.setCloseStream(false); document.open(); PdfPTable table = new PdfPTable(2);// new PdfTable(periodList.size() + 1); // the cell object PdfPCell cell = new PdfPCell(new Paragraph ("Merry Moore")); cell.setColspan(2); table.addCell(cell); System.out.println("Added new paragraph"); // now we add a cell with rowspan 2 cell = new PdfPCell(new Phrase("Cell with rowspan 2")); cell.setColspan(2); table.addCell(cell); System.out.println("Added new cell"); // we add the four remaining cells with addCell() table.addCell("row 1; cell 1"); table.addCell("row 1; cell 2"); table.addCell("row 2; cell 1"); table.addCell("row 2; cell 2"); document.add(table); System.out.println("Added table to document"); document.close(); return outputStream.toByteArray(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload