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