Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC: PDF generation from JSP page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC: PDF generation from JSP page

    I am looking for a solution to generate a PDF from output that we get from a JSP. We are using Spring MVC and using Spring binding tags and JSTL in JSP's.

    I do not want to re-do anything in the presentation and want to use a print-preview page into PDF.

    Has anyone using Spring MVC implemented a solution to generate a PDF file from output of a JSP page?

  • #2
    For PDF generation I use AbstractController and AbstractPdfView
    Code:
    public class CustomerOrderPdfController extends AbstractController {
        
        protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
            CustomerOrder order = new CustomerOrder();
            order.setQty(Integer.value(100));
            return new ModelAndView(new CustomerOrderPdfView(), "customerOrder", order);
        }
    
    }
    Code:
    public class CustomerOrderPdfView extends AbstractPdfView {
    
      protected void buildPdfDocument(Map model,
                                      Document doc,
                                      PdfWriter writer,
                                      HttpServletRequest req,
                                      HttpServletResponse resp)
                                      throws Exception
      {
    	  CustomerOrder customerOrder =  (CustomerOrder) model.get("customerOrder");
              doc.add(new Paragraph("QTY :"+customerOrder.getQty()));
      }
    }

    Comment


    • #3
      Thank you Prohor, I have not yet heard of that class, what Spring versions is it compatible with?

      Comment


      • #4
        CustomerOrderPdfController and CustomerOrderPdfView it's my example class.
        I use Spring 2.5.6 and libs inside have org.springframework.web.servlet.view.document.Abst ractPdfView class.

        Comment


        • #5
          I was talking about the Spring class you were extending my friend

          Comment

          Working...
          X