1.下载:
https://download.csdn.net/download/q908544703/85277974
2.web端代码:
getOnlineFile:function(projectAttachId){
//http://localhost:8080/km/attachFileEs/downloadPdf?projectAttachId='11111'
var FileUrl =baseUrl + 'km/attachFileEs/downloadPdf?projectAttachId='+ projectAttachId+"&document.title=33.pdf";
var urls="../../pdf/web/viewer.html?file="+encodeURIComponent(FileUrl);
window.open( urls);
}
//注意参数 filename是额外处理的 文件名获取不到 需额外传参数 在pdfjs里面处理document.title
实际打开地址
http://127.0.0.1:8091/src/page/ceo/km/html/pdf/web/viewer.html?file=%2Fkm%2FattachFileEs%2FdownloadPdf%3FprojectAttachId%3D1797d2d56281464d970de28f2be0a93f%26document.title%3D33.pdf
3.java 代码实现
/**
* 预览pdf文件
* @author Mike
* @param request
* @param response
* @param projectAttachId
*/
@RequestMapping(value = "/downloadPdf", method = RequestMethod.GET)
public void pdfStreamHandeler(HttpServletRequest request, HttpServletResponse response,String projectAttachId) {
String filePath = "F:\\ZFU资料\\年中十讲笔记完整版.pdf";
// System.out.println(fileName);
File file = new File(filePath);
byte[] data = null;
FileInputStream input=null;
try {
input = new FileInputStream(file);
data = new byte[input.available()];
input.read(data);
response.getOutputStream().write(data);
input.close();
} catch (Exception e) {
System.out.print("pdf文件处理异常:" + e.getMessage());
} finally {
try {
input.close();
} catch (IOException e) {
logger.error("InputStream关闭异常", e);
}
}
}