I want to open a blank PDF in browser in my application. I am using the Spring Web model-view-controller (MVC) framework.
Here the code
@Override
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
byte[] data = "No file attached".getBytes();
String fileName = "NofileFound.pdf";
response.setHeader("Content-Disposition","attachment; filename="+fileName);
response.setContentType("application/pdf");
OutputStream out = response.getOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(new Document(), new FileOutputStream("NofileFound.pdf"));
document.open();
document.add(new Paragraph("test"));
document.close();
writer.close();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfWriter.getInstance(document, byteArrayOutputStream);
data = byteArrayOutputStream.toByteArray();
out.write(data);
out.flush();
out.close();
return null;
}
But when I open the file I got this error:
not a supported file type