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