How to export table displayed on jsp to pdf in java strust2

后端 未结 5 1281
梦如初夏
梦如初夏 2020-12-18 10:56

This is my data display in table format. I want to show as it is in PDF without using display tag library of struts2.

5条回答
  •  一向
    一向 (楼主)
    2020-12-18 11:50

            Finaly i got the solution here is the code
    
    
              
    
        
    
           In the action class  
    public String ExportPDF()
        {   
                tablestruct = ""+tablestruct+"";
                        //System.out.println("After concat "+tablestruct);
                        try{
                            String filePath = ServletActionContext.getServletContext().getRealPath("/testpdf.pdf");
                            System.out.println(filePath);
                            Document document=new Document(PageSize.LETTER);
                            PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(filePath));
                               document.open();
                               HTMLWorker htmlWorker = new HTMLWorker(document);
                               htmlWorker.parse(new StringReader(tablestruct));
                                document.close();
                                System.out.println("Done");
                                File file = new File(filePath);
                                inputStream = new DataInputStream( new FileInputStream(file));
                          }
                          catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                    }     
    

提交回复
热议问题