先上效果图代码下面会跟上:
功能实现代码:
@RequestMapping("/getPdfView")标签:浏览器,预览,java,IOUtils,pdf,PDF,response From: https://www.cnblogs.com/changsu/p/16944289.html
public void pdf(HttpServletRequest request, HttpServletResponse response) {
try {
File file = new File("F:/text.pdf");
FileInputStream fileInputStream = new FileInputStream(file);
response.setHeader("Content-Type", "application/pdf");
OutputStream outputStream = response.getOutputStream();
IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream);
} catch(Exception e) {
e.printStackTrace();
}
}
以上预览PDF的方式是运用到了浏览器上自带的查看PDF插件,适用于,只要浏览器能打开PDF就可以。目前亲测(Edge、谷歌、火狐都可使用) 其他浏览器未知。