Issue
I wish to show this file on page but this code make a direct download
<a th:href="@{/pdf/Manjaro-User-Guide.pdf}">Show Pdf file</a>
I'm using Spring-Thymeleaf
Thanks!
Solution
I found the solution by commenting the line below
//response.setHeader("Content-Disposition", "attachment; filename=\"demo.pdf\"");
Here is the code example:
@GetMapping(value = "/pdf")
public void showPDF(HttpServletResponse response) throws IOException {
response.setContentType("application/pdf");
//response.setHeader("Content-Disposition", "attachment; filename=\"demo.pdf\"");
InputStream inputStream = new FileInputStream(new File(rootLocation + "/Manjaro-User-Guide.pdf"));
int nRead;
while ((nRead = inputStream.read()) != -1) {
response.getWriter().write(nRead);
}
}
Thanks!
Answered By - Ravo
Answer Checked By - Marie Seifert (JavaFixing Admin)