步驟如下:
1.下載pdfJs到本地(官網下載地址),放到項目根目錄下的static文件夾內,將文件命名爲pdfJs。
如下圖
2. 使用iframe打開
<iframe id="pdfPlayer" src="URL" frameborder="0" width="100%" height="600px"></iframe>
或者:<iframe id="pdfPlayer" :src="pdfUrl3" frameborder="0" width="100%" height="600px"></iframe>
需要注意的是: file參數中默認只允許傳簡單路徑比如:http://www.aaa.com/aa.pdf. 如果你要瀏覽的pdf路徑需要傳參數的話。 這時候直接傳入的話會解析出錯, 因爲pdf.js無法判斷參數是viewer.html的參數呢還是aa.pdf的參數。所以,
URL 必須進行encode編碼 ,encodeURIComponent() 把字符串編碼爲 URI 組件