-1

This is the code I am using in my JSP to render PDF file

FileInputStream fis = new FileInputStream(path);

int b = 0;
while ((b = fis.read()) != -1) 
{
   out.write(b);
}

Path contains location of PDF file stored on local disk. Problem: Its rendering stupid text. I could not even figure out what it is.

Any help is appreciated. What code to add/modify

1 Answers1

0

I think the very least you are going to need to set the response type to "application/pdf". What is that out variable? If its' an HttpServletResponse, then you can do something like:

response.setContentType("application/pdf");

Many approaches for doing this are outlined here: Displaying pdf in jsp

Community
  • 1
  • 1
Robert Moskal
  • 21,737
  • 8
  • 62
  • 86
  • Actually the web page is divided into two divisions. 1 for displaying PDF and the other has a form which takes inputs When I added response.setContentType("application/pdf"); to the code, web page is blank – Bhargava Mourya Apr 20 '14 at 20:11
  • So that code snippet above is embedded in the jsp or its' running server side in a servlet or a spring route handler or something? – Robert Moskal Apr 20 '14 at 20:54