html 顯示doc文件

爲了方便,項目需要網頁顯示客戶提供的一份word文檔

獲取絕對路徑會直接下載文件

尋求解決辦法

1.JS獲取word文檔內容到html頁面

   ActiveXObject只支持ie,其他瀏覽器並不適用

2.https://blog.csdn.net/qxianx/article/details/81317894

<iframe style="width: 100%;min-height: 600px;" src='https://view.officeapps.live.com/op/view.aspx?src=${pageContext.servletContext.contextPath}/app/basedata/receive/pdfView.jsp' width='100%' height='100%' frameborder='1'>
	

3.轉pdf

pdf在線預覽包

//引用 
function  process(){
			 window.open ("${pageContext.servletContext.contextPath}/app/basedata/receive/pdfView.jsp", "視頻播放窗口", "height=542, width=950, top=110,left="+(window.screen.width-950)/2+", toolbar=no, menubar=no, scrollbars=no, location=no, status=no"); //寫成一行
        } 
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <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>
    <script src="${pageContext.servletContext.contextPath}/jslib/pdf.js" type="text/javascript"></script>
        <script src="${pageContext.request.contextPath}/jslib/jquery/jquery-1.8.3-min.js"></script>
    <script type="text/javascript">
   $(function(){
   showPdf();
   });
        function showPdf() {
            var container = document.getElementById("container");
            container.style.display = "block";
            var url = '${pageContext.servletContext.contextPath}/file/事故報告流程圖求科室意見後.pdf';
            PDFJS.workerSrc = '${pageContext.servletContext.contextPath}/jslib/pdf.worker.js';
            PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
                pdf.getPage(1).then(function getPageHelloWorld(page) {
                    var scale = 1;
                    var viewport = page.getViewport(scale);
                    var canvas = document.getElementById('the-canvas');
                    var context = canvas.getContext('2d');
                    canvas.height = viewport.height;
                    canvas.width = viewport.width;
                    var renderContext = {
                        canvasContext: context,
                        viewport: viewport
                    };
                    page.render(renderContext);
                });
            });
        }
    </script>
</head>
<body>
    <div id="container" style="display: none;">
        <div class="lightbox"></div>
        <div id="pop" class="pop">
            <canvas id="the-canvas"></canvas>
        </div>
    </div>
</body>
</html>

4.推薦(微軟提供的api有諸多限制)

下載pdfjs。百度雲   官網

通過訪問 http://127.0.0.1:8080/PDF.js/web/viewer.html?file=你的pdf地址

 function  process(){
 window.open ("${pageContext.servletContext.contextPath}/app/basedata/receive/pdf/web/viewer.html?file=${pageContext.servletContext.contextPath}/file/事故報告流程圖求科室意見後.pdf", "視頻播放窗口", "height=542, width=950, top=110,left="+(window.screen.width-950)/2+", toolbar=no, menubar=no, scrollbars=no, location=no, status=no"); //寫成一行
        } 
   

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章