When I am trying to open a PDF through a
Servlet it is popping with an acrobat error with the message
"The file is damaged and could not be repaired"
I am using the following code to display the pdf file from the serlvet,
File pdfFile = new File(filePath);
OutputStream responseOutputStream = resp.getOutputStream();
resp.setContentType("application/pdf");
resp.setHeader("Content-disposition", "attachment;filename=\"" + file + "\"");
resp.setContentLength((int)filePath.length());
FileInputStream fileInputStream = new FileInputStream(pdfFile);
int size = fileInputStream.available();
byte[] content = new byte[size];
fileInputStream.read(content);
responseOutputStream.write(content);
responseOutputStream.flush();
fileInputStream.close();
responseOutputStream.close();
The same code works fine when the pdf contains only text content.
But it doesn't work when PDF contains text content with images.
Could anyone help me to solve this issue..