How to display a pdf file in browser using java
Display PDF in browser using Java from response
response.setHeader("Content-Disposition", "inline; filename='" + pdfName + "'");
response.setContentLength((int) FileInputStream input = new FileInputStream("File.pdf").length());

The above lines of code can be used to send a response to the view( like .jsp) as a pdf.  This will open the pdf in the browser and not make the pdf downloadable.

Display PDF in browser view page
To indicate to the browser that the file should be viewed in the browser :
Content-Type : application/pdf

Content-Disposition : inline; filename.pdf

To have the file downloaded rather than viewed:
Content-Type : application/pdf

Content-Disposition : attachment; filename.pdf

No comments :

Post a Comment