PDFObject.js,在页面显示PDF文件
PDFObject的官网:
使用pdfobject.js实现在线浏览PDF
https://blog.csdn.net/beyond__devil/article/details/78826826
PDFobject.js官方api简易说明
https://blog.csdn.net/badgirl_hong/article/details/53139478
PDF预览之PDFObject.js总结
https://blog.csdn.net/i_dont_know_a/article/details/80707963
http://www.cnblogs.com/pejsidney/p/9019143.html
PDFObject插件不能加载远程链接的问题
https://blog.csdn.net/liujun_for_java/article/details/85172817
2.前端预览PDF:PDFObject、PDF.js 之对比
https://blog.csdn.net/liuyaqi1993/article/details/77822946
实战:
1.引入js
<script type="text/javascript" src="../build/pdfobject.js"></script>
2.html
<div id="pdfs">
</div>
3.js
var string = window.location.search; //获取url过来的参数
// console.log(string)
var str = string.split('=')[1];
// console.log(str)
var s = str.split("+")
// console.log(s)
if (typeof(s[2]) == 'undefined' || s[2] =='') {
s[2] = false;
}
// var url = s[0] +"filepreview/loadFileByPdfObject?fileId=" + s[1];
var url = s[0] +"filepreview/loadFile?isNeedWaterMark="+ s[2]+"&fileId=" + s[1];
var op = {
withd:"920px",
height:"460px"
}
console.log(url);
// 我的pdf文件放在项目的pdf文件夹下,名字叫做Java.pdf
PDFObject.embed("Java.pdf", "#my-container", options);
//url为远程连接,也就是后端输出pdf流的地方
PDFObject.embed(url,'#pdfs',op);
注意 后端输出需要设置为
response.setContentType("application/pdf;charset=UTF-8");
application:某二进制的一个附件
octet-stream:子类型,不确定下载文件的通用指定
pdf:指定为PDF
代码块