实现pdf上传、预览、下载(pdfobject.js)

使用pdfobject.js实现预览和下载

<html>
<head>
<title>pdf_view</title>
</head>
<body>
	<div id="pdf"></div>
</body>
<script type="text/javascript" src="pdfobject.js"></script>
<script type="text/javascript">
window.onload = function() {
        PDFObject.embed("pdf路径", "#pdf");
    };
</script>
</html>

文件上传

input标签

<input id="addFile" type="file"  accept="application/pdf">

获取上传文件的路径

var file = $('#addFile').get(0).files[0];
src = getFilePath(file);  
function getFilePath(file){
		//获取文件路径
		var url = null;
            if (window.createObjcectURL != undefined) {
                url = window.createOjcectURL(file);
            } else if (window.URL != undefined) {
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) {
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
	}
 PDFObject.embed(src, "#pdf");

猜你喜欢

转载自blog.csdn.net/weixin_38260896/article/details/88812767