ViewPDF.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.kmall.admin.utils.pdf;
  2. import com.kmall.api.entity.exportpdf.PDFGoodsDto;
  3. import com.lowagie.text.Document;
  4. import com.lowagie.text.pdf.PdfWriter;
  5. import org.springframework.web.servlet.view.document.AbstractPdfView;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import java.util.Date;
  9. import java.util.Map;
  10. public class ViewPDF extends AbstractPdfView {
  11. @Override
  12. protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
  13. HttpServletRequest request, HttpServletResponse response) throws Exception {
  14. String fileName = new Date().getTime()+"_quotation.pdf"; // 设置response方式,使执行此controller时候自动出现下载页面,而非直接使用excel打开
  15. response.setCharacterEncoding("UTF-8");
  16. response.setContentType("application/pdf");
  17. response.setHeader("Content-Disposition","filename=" + new String(fileName.getBytes(), "iso8859-1"));
  18. PdfUtil pdfUtil = new PdfUtil();
  19. String type = (String) model.get("type");
  20. PDFGoodsDto pdfGoodsDto = (PDFGoodsDto) model.get("dto");
  21. String fontUrl = (String) model.get("fontUrl");
  22. String uploadDir = (String) model.get("uploadDir");
  23. String head = (String) model.get("head");
  24. String headUrl = (String) model.get("headUrl");
  25. pdfUtil.createPDF(document,writer,pdfGoodsDto,type,fontUrl,uploadDir,head,headUrl);
  26. }
  27. }