总结pdf放到页面上预览用法

PDF.JS的链接

链接:https://pan.baidu.com/s/1HlwqzzDKLe2Uu_a6sJeyCg

密码:vyms

------------------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
       <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <style type="text/css">
        .lightbox{
            position: fixed;
            top: 0px;
            left: 0px;
            height: 100%;
            width: 100%;
            z-index: 7;
            opacity: 0.3;
            display: block;
            background-color: rgb(0, 0, 0);
        }
        .pop{
            position: absolute;
            left: 50%;
            width: 894px;
            margin-left: -447px;
            z-index: 9;
        }
    </style>

<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>芳华图书馆</title>
</head>
<body>
<form action="/syslogin/to_login.do" method="post">
<input type="submit" value="aa">
  <h1><a href="javascript:void(0)" target="_blank" οnclick="showPdf()">显示pdf文档</a></h1>
  <!--   <div id="container" style="display: none;">
        <div class="lightbox"></div>
        <div id="pop" class="pop">
        
        </div>
    </div> -->

</form>
	<!-- pdf.js的项目路径 -->
 <script type="text/javascript" src="/static/pdf/build/pdf.js" ></script>
 <!-- 配置pdf的路径,也可以在下面showPdf配置 -->
 <script type="text/javascript" src="/static/pdf/build/pdf.worker.js" ></script>
<script type="text/javascript">
</script>
<script type="text/javascript">
        function showPdf() {
            var container = document.getElementById("container");
            //pdf在项目里面的相对路径
            var url = '/uploadFiles/uploadDoc/test8.pdf';
            PDFJS.workerSrc = '/static/pdf/build/pdf.worker.js';
            PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
            	//for循环渲染每一页,要从1开始
            	 for (var i = 1; i < pdf.numPages; i++) {
                pdf.getPage(i).then(function getPageHelloWorld(page) {
                    var scale = 1.5;
                    var viewport = page.getViewport(scale);
                    var canvas = document.createElement('canvas');
                    var context = canvas.getContext('2d');
                    canvas.height = viewport.height;
                    canvas.width = viewport.width;
                    //这里存放到body下可以自行修改到要放的div里面
                    document.body.appendChild(canvas);
                     var renderContext = {
                        canvasContext: context,
                        viewport: viewport
                    };  
                    page.render(renderContext);
                });
            }
            });
        }
    </script>


</body>
</html>

----------------------------------------


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值