经过我后来的研究发现,pdfjs并不支持ie10及以下,请不要被一些无良博客欺骗了!!
https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#which-browsers-are-supported
下载pdf.js文件http://mozilla.github.io/pdf.js/
- 解压文件全部将其放置到项目web或者webapp下
- 使用XX\pdfjs/web/viewer.html能看到一个pdf文件就说明加载成功了
- 普通的使用方法其他文章也能看见,跨域问题等请看别的博客,一会推荐
- 此处是mongodb二进制文件流输出
- window.open('/XX/resources/front/js/pdfjs/web/viewer.html?file='+encodeURIComponent(fileurl));
-
/** * 根据项目id查找附件-预览 * @param * @return */ @RequestMapping(value="/XX") public void XX(String proid ,HttpServletResponse resp) { if(proid !=null && !"".equals(proid)){ //获取项目详情数据 try{ OutputStream os = resp.getOutputStream(); TbAttachment atta = tbattachmentservice.selectByProId(proid); if(atta != null){ gsMongoClient.downloadLt15M(name, atta.getId(), os); } }catch(Exception e){ e.printStackTrace(); } } }
mongodb下载文件流
@Override public void downloadLt15M(String collName, String _id, OutputStream os) throws IOException { MongoCollection<Document> collection = GetDatabase().getCollection(collName); FindIterable<Document> docIter = collection.find(Filters.eq(ID, _id)); Binary binary = (Binary) docIter.first().get(FILE); byte[] file= binary.getData(); BufferedOutputStream bos=new BufferedOutputStream(os); bos.write(file); bos.flush(); bos.close(); os.close(); }
博客推荐
-
https://blog.csdn.net/yuhaifei_123/article/details/79174057?utm_source=blogxgwz5
-
https://blog.csdn.net/jianyuerensheng/article/details/79570781
-
https://blog.csdn.net/l_ai_yi/article/details/82388497#commentBox