springboot通过浏览器在线预览PDF文件
/**
* 获取PDF信息
* @param response
*/
@GetMapping(value = "/getPdfInfo")
public void getPdf(HttpServletResponse response) {
InputStream is=null;
OutputStream outputStream=null;
try {
Resource resource = new ClassPathResource("./***.pdf");
is = resource.getInputStream();
outputStream = response.getOutputStream();
IOUtils.copy(is, outputStream);
is.close();
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(null!=is){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if(null!=outputStream){
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
效果
版权声明:本文为u014417605原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。