react----項目實際過程中pdf.js的使用

遇到的問題
1.當請求爲https的請求的時候,如果返回的PDF的鏈接是http的鏈接,那麼pdf.js打開的時候會報錯
2.pdf.js的核心文件可以直接放到服務器下面,不用進行項目的報錯輸出
3.pdf.js在請求pdf完成之後,自動啓用打印的功能
//viwer.html頁面嵌入了內聯的腳本進行執行

  <script>
    var interval = setInterval(function(){
        if (PDFViewerApplication.pdfDocument == null) {
            console.info('pdf 加載中...');
        } else {
            console.info('pdf 加載完成...');
            window.print();
            //加載完成
            clearInterval(interval);
        }
    }, 1000);
  </script>

4.正常情況下,本地開發的時候,pdf.js讀取鏈接會報錯,需要將原本代碼的東西註釋掉一點
5.如何將pdf的打開方式設置爲這種新窗口彈出打開?
在這裏插入圖片描述
代碼實現

var isWidth = window.screen.availWidth
var isHeight = window.screen.availHeight
var feature =	"width="+isWidth+",
				height="+isHeight+",
				top=0,left=0,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,
				modal=no,titlebar=no,status=no";
window.open('/static/pdf/web/viewer.html?file='+encodeURIComponent(res.data.data.fileLink), 'newwindow',feature)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章