问题描述:
com.itextpdf.text.ExceptionConverter: The document has no pages.
Caused by: java.io.IOException: The document has no pages.
问题分析:
1、使用模板导出PDF文件时,由于没有数据导致没有读取模板进行生成内容。
public void getTemplatePDF(HttpServletResponse response) {
try {
// 模板路径
String templatePath = "doc/模板.pdf";
ServletOutputStream os = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PdfStamper stamper = null;
PdfReader reader = null;// 读取pdf模板
Document doc = null;
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName=测试.pdf");
os = response.getOutputStream();// 输出流
doc = new Document();
PdfCopy copy = new PdfCopy(doc, os);