您的位置:首页 > 移动开发 > Objective-C

js pdf展示插件(pdfobject)

2017-11-08 19:29 501 查看
我的环境:
前端: thymeleaf    后台springmvc

前端代码:
引入相关包:
<script th:src="@{/assets/js/pdf/pdfobject.js}"></script>

html容器:

<div  id="pdfDiv" style="height:600px;width:1200px">

</div>


js调用:

window.onload = function (){
var mid=getUrlParam("mid");
var success = new PDFObject({ url: "http://localhost:9080/ymlib/administrator/manuscriptManagement/getPdf?mid="+mid}).embed("pdfDiv");
}


控制层代码:

@RequestMapping(value = "/getPdf", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getPdf(@RequestParam(value = "mid") String mid) {
Manuscript  manuscript=manuscriptRepository.findOne(mid);

Query query = new Query(Criteria.where("_id").is(new ObjectId(manuscript.getFileId())));
GridFSDBFile file_check = gridFsOps.findOne(query);
InputStream in = file_check.getInputStream();
return ResponseEntity.ok().contentLength(file_check.getLength())
.cacheControl(CacheControl.maxAge(3600, TimeUnit.SECONDS)).contentType(MediaType.valueOf("application/pdf"))
.body(new InputStreamResource(in));
}


效果图如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: