67,550
社区成员




ServletActionContext.getResponse().setHeader(
"Content-disposition",
"attachment; filename="
+ URLEncoder.encode("报价单展示表.pdf", "UTF-8"));
就解决了。Document document = new Document(PageSize.A4, 10, 10, 10, 10); HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/pdf");
table = new Table(12);//设置列数为3列
table.setBorderWidth(1); //将边框宽度设为1
table.setBorderColor(new Color(0, 0, 255));
table.setPadding(1);
table.setSpacing(1);
//上面两个代码是设置单元格的间距
Cell cell = new Cell(new PDFParagraph("案例信息")); //设置表头的名称
cell.setHeader(true);//是将该单元格作为表头信息显示
cell.setColspan(12);//指定了该单元格占4列,为表格添加表头信息时
table.addCell(cell);
table.endHeaders();
table.addCell(new PDFParagraph("案例代号"));
table.addCell(new PDFParagraph("案例名称"));
table.addCell(new PDFParagraph("案例状态"));
table.addCell(new PDFParagraph("开启日期"));
table.addCell(new PDFParagraph("产品线名称"));
table.addCell(new PDFParagraph("通路名称"));
table.addCell(new PDFParagraph("销售区域名称"));
table.addCell(new PDFParagraph("联系人"));
table.addCell(new PDFParagraph("公司"));
table.addCell(new PDFParagraph("案例型态"));
table.addCell(new PDFParagraph("附件数量"));
table.addCell(new PDFParagraph("备注"));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PdfWriter.getInstance(document, buffer);
document.open();
document.add(table);
document.close();
response.setContentLength(buffer.size());//测试
ServletOutputStream out = response.getOutputStream();
buffer.writeTo(out);
out.flush();
response.setContentType()的String参数及对应类型
<option value="image/bmp">BMP</option>
<option value="image/gif">GIF</option>
<option value="image/jpeg">JPEG</option>
<option value="image/tiff">TIFF</option>
<option value="image/x-dcx">DCX</option>
<option value="image/x-pcx">PCX</option>
<option value="text/html">HTML</option>
<option value="text/plain">TXT</option>
<option value="text/xml">XML</option>
<option value="application/afp">AFP</option>
<option value="application/pdf">PDF</option>
<option value="application/rtf">RTF</option>
<option value="application/msword">MSWORD</option>
<option value="application/vnd.ms-excel">MSEXCEL</option>
<option value="application/vnd.ms-powerpoint">MSPOWERPOINT</option>
<option value="application/wordperfect5.1">WORDPERFECT</option>
<option value="application/vnd.lotus-wordpro">WORDPRO</option>
<option value="application/vnd.visio">VISIO</option>
<option value="application/vnd.framemaker">FRAMEMAKER</option>
<option value="application/vnd.lotus-1-2-3">LOTUS123</option>