I am using the below code , But this one is automatically download the PDF file on my local machine. I don,t want to download this by default. I want to show the pdf file on UI or .
response.setHeader("Content-Disposition", "attachment;filename=\"" + reportFileName + ".pdf\"");
response.setContentType(reportType.getContentType());
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
LavanteReportFooter event = new LavanteReportFooter();
writer.setPageEvent(event);
document.open();
PdfPTable table = new PdfPTable(reportColumnHeaders.size());
table.setWidthPercentage(100); //Width 100%
table.setSpacingBefore(10f); //Space before table
table.setSpacingAfter(10f); //Space after table
Font pdfTitleFont = FontFactory.getFont(FontFactory.HELVETICA);
pdfTitleFont.setSize(12f);
pdfTitleFont.setStyle(Font.BOLD);
Paragraph pdfTitle = new Paragraph(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(cell);
}
Font dateFont = FontFactory.getFont(FontFactory.HELVETICA);
dateFont.setSize(8f);
table.setSplitRows(false);
table.setComplete(false);
int rowNum = 1;
Iterator<List<String>> iterator = dataRows.iterator();
while (iterator.hasNext()) {
if(rowNum % 200 == 0){
document.add(table);
}
List<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));
}else{
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(cell);
}
row.clear();
iterator.remove();
rowNum = rowNum +1;
}
table.setComplete(true);
document.add(table);
document.close();
writer.close();
}