PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > Laravel教程 > 正文

    uniapp pdf预览

    作者:admin来源:网络浏览:时间:2021-01-03 11:54:54我要评论
    导读:uniapp pdf预览,一个是通过第三方软件查看pdf,另一种是通过pdf.js在uniapp中查看的
    uniapp pdf预览

    1. //一个是通过第三方软件查看pdf 
    2.  uni.downloadFile({ //通过uniapp的api下载下来 
    3.           url: 'test.pdf'
    4.           success: function (res) { 
    5.           var filePath = res.tempFilePath; 
    6.          uni.openDocument({ 
    7.          filePath: filePath, 
    8.          success: function (FileRes) { 
    9.          console.log('打开文档成功'); 
    10.           } 
    11.         }); 
    12.         } 
    13.       });        
    14. //另一种是通过pdf.js在uniapp中查看的 
    15. //新建webView.vue 
    16. <template> 
    17.     <view style="width: 100%;" > 
    18.         <web-view  :src="allUrl"></web-view> 
    19.     </view> 
    20. </template> 
    21.   
    22. <script> 
    23.     export default { 
    24.         data() { 
    25.             return { 
    26.         src: ''
    27.                 allUrl:''
    28.         viewerUrl: '/hybrid/html/web/viewer.html'// 格式化文件流的一个js 文件 文末会分享出来 
    29.             } 
    30.         }, 
    31.         onLoad(options) { 
    32.                 let fileUrl = encodeURIComponent("pdf的地址"// encodeURIComponent 函数可把字符串作为 URI 组件进行编码。 
    33.                 this.allUrl = this.viewerUrl + '?file=' + fileUrl 
    34.           } 
    35.     } 
    36. </script> 
    37. ////////////////////////////////////////////////// 
    38. //然后引入文件夹hybrid放在项目根目录下 
    39.   
    40. //然后就传路径到webView 
    41. //列如 
    42. uni.navigateTo({ 
    43.     url:'../filePreview?url='+你的pdf路径 
    44. }) 

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-153-6471-1.html
    相关热词搜索: uniapp pdf预览
    下一篇:laravel8 跨域