pdf文件浏览器在线预览
2023-04-25 本文已影响0人
让你变好的过程从来都不会很舒服
@RequestMapping(value = "/showpdf.do")
public void showpdf(HttpServletRequest request, HttpServletResponse response, Model model) {
try {
File file = new File("E:/123.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文件浏览器在线预览
*
* @param attaOid
* @return
* @author jiaq
* @date 2023年04月26日
*/
@RequestMapping("/showpdf.do")
public void showPdf(HttpServletResponse response,String attaOid){
File file = new File("E:/123.pdf");
if (file.exists()){
byte[] data = null;
try {
FileInputStream input = new FileInputStream(file);
data = new byte[input.available()];
input.read(data);
response.getOutputStream().write(data);
input.close();
} catch (Exception e) {
System.out.println(e);
}
}else{
return;
}
}
