uniapp 瀏覽pdf文件


//一個是通過第三方軟件查看pdf uni.downloadFile({ //通過uniapp的api下載下來       url: 'test.pdf', success: function (res) {       var filePath = res.tempFilePath;  uni.openDocument({  filePath: filePath,  success: function (FileRes) {  console.log('打開文檔成功');       } });     }   }); //另一種是通過pdf.js在uniapp中查看的 //新建webView.vue <template> <view style="width: 100%;" > <web-view :src="allUrl"></web-view> </view> </template> <script> export default { data() { return { src: '', allUrl:'', viewerUrl: '/hybrid/html/web/viewer.html', // 格式化文件流的一個js 文件 文末會分享出來 } }, onLoad(options) { let fileUrl = encodeURIComponent("pdf的地址") // encodeURIComponent 函數可把字符串作為 URI 組件進行編碼。 this.allUrl = this.viewerUrl + '?file=' + fileUrl } } </script> ////////////////////////////////////////////////// //然后引入文件夾hybrid放在項目根目錄下 //然后就傳路徑到webView //列如 uni.navigateTo({ url:'../filePreview?url='+你的pdf路徑 }) //附上pdf文件鏈接:https://pan.baidu.com/s/1TMj1b5v6AX-orYJNYZCFGQ 提取碼:2020


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM