我正在使用下面的代码,但是这个代码会在我的本地计算机上自动下载PDF文件。我不想,默认情况下要下载它。我想在UI或上显示pdf文件。


response.setHeader(“Content-Disposition”,“attachment; filename = \”“+ reportFileName +”。pdf \“”);
 response.setContentType(reportType.getContentType());


 Document document = new Document();
 PdfWriter writer = PdfWriter.getInstance(document,response.getOutputStream());

 LavanteReportFooter事件= new LavanteReportFooter();
 writer.setPageEvent(事件); 
 document.open();

 PdfPTable table = new PdfPTable(reportColumnHeaders.size());
 table.setWidthPercentage(100); //宽度100%
 table.setSpacingBefore(10F); //表格前的空格
 table.setSpacingAfter(10F); //桌子后面的空格

字体pdfTitleFont = FontFactory.getFont(FontFactory.HELVETICA);
 pdfTitleFont.setSize(12F);
 pdfTitleFont.setStyle(Font.BOLD);

段落pdfTitle = new段落(reportFileName,pdfTitleFont);
 pdfTitle.setAlignment(Element.ALIGN_LEFT);

 PdfPCell pdfTitleCell = new PdfPCell(pdfTitle);
 pdfTitleCell.setBackgroundColor(Color.WHITE);
 pdfTitleCell.setHorizontalAlignment(Element.ALIGN_LEFT);
 pdfTitleCell.setColspan(reportColumnHeaders.size());
 pdfTitleCell.setBorder(Rectangle.NO_BORDER);

 table.addCell(pdfTitleCell);

 PdfPCell blankCell = new PdfPCell(new Paragraph(“”));
 blankCell.setBackgroundColor(Color.WHITE);
 blankCell.setHorizontalAlignment(Element.ALIGN_LEFT);
 blankCell.setColspan(reportColumnHeaders.size());
 blankCell.setBorder(Rectangle.NO_BORDER);

 table.addCell(blankCell);
 table.addCell(blankCell);

 Font headerFont = FontFactory.getFont(FontFactory.HELVETICA);
 headerFont.setSize(9F);

 for(String reportColumnHeader:reportColumnHeaders){
 PdfPCell cell = new PdfPCell(new Paragraph(reportColumnHeader,headerFont));
 cell.setPadding(4);
 cell.setHorizontalAlignment(Element.ALIGN_LEFT);
 cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
 cell.setBorderWidth(0.5F);
 cell.setBorderColor(new Color(173,173,172));
 cell.setBackgroundColor(new Color(247,247,253));
 table.addCell(细胞);
 }

字体dateFont = FontFactory.getFont(FontFactory.HELVETICA);
 dateFont.setSize(8F);

 table.setSplitRows(假);
 table.setComplete(假);

 int rowNum = 1;
迭代<列表与LT;字符串>> iterator = dataRows.iterator();
 while(iterator.hasNext()){

 if(rowNum%200 == 0){
 document.add(表);
 }

列表与LT; java.lang.String中> row =(List< java.lang.String>)iterator.next();
 for(String column:row){
 PdfPCell cell = new PdfPCell(new Paragraph(column,dateFont));
 if(rowNum%2 == 0){
 cell.setBackgroundColor(new Color(247,247,253));
 }其他{
 cell.setBackgroundColor(Color.WHITE);
 }
 cell.setPadding(4F);
 cell.setBorderWidth(0.5F);
 cell.setBorderColor(new Color(173,173,172));
 cell.setHorizontalAlignment(Element.ALIGN_LEFT);
 cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
 table.addCell(细胞);
 }
 row.clear();
 iterator.remove();
 rowNum = rowNum +1;
 }

 table.setComplete(真);
 document.add(表);
 document.close();
 writer.close();
 }
 代码>