美文网首页
微信小程序打开预览PDF

微信小程序打开预览PDF

作者: 剑圣_盖小聂 | 来源:发表于2021-01-28 10:55 被阅读0次

iso打开没有下载,安卓打开有下载:

<view class='pdf_box' catchtap='downLoadPdf' data-url="https://baidu.pdf">
            <image src='../../images/pdf.png' mode='widthFix'></image>
            <label>下载资源</label>
</view>

JS:

  downLoadPdf(e){
    var url = e.currentTarget.dataset.url;
    wx.showToast({
      title: '打开中…',
      icon: "loading",
      duration: 100000
    })

  if (url){
    
    wx.downloadFile({
      url: url,
      header: {
        'content-type': 'application/json',
      },
      // filePath: wx.env.USER_DATA_PATH + "/res",
      success: function (res) {
        console.log(res)
        var Path = res.tempFilePath              //返回的文件临时地址,用于后面打开本地预览所用 
        wx.openDocument({
          filePath: Path,
          success: function (res) {          
              wx.hideToast();

          }
        })
      },
      fail: function (res) {
        console.log(res);
        wx.showToast({
          title: '下载失败',
          icon: "loading",
          duration: 1000
        })
      }
    })
  }
  
  },

相关文章

网友评论

      本文标题:微信小程序打开预览PDF

      本文链接:https://www.haomeiwen.com/subject/grsazktx.html