关于在小程序打开PDF 问题?

发布于 5 年前作者 zjiang7525 次浏览最后编辑 5 年前来自 ask

有个需求需要在小程序中打开PDF,直接预览,然后在体验版或者真机预览都能直接预览PDF,但是在正式版本上没办法预览,下面是我的代码,相关业务域名都配置了

2 回复
junyu
junyu1 楼4 年前

complete 打印下回调看看。

xia13
xia132 楼1 年前

试试把文件类型加上 

 /* 打开文档
  * @param fileUrl: 文件地址
  * @param filetype: 文件类型
  */
  openDocument(fileUrl, filetype) {
    filetype=filetype || "";
    wx.showLoading({
      title: '加载中...',
    })
    wx.downloadFile({
      url: fileUrl,
      success: res => {
          wx.hideLoading();
          const filePath = res.tempFilePath;
          wx.openDocument({
            showMenu:true,
            filePath: filePath,
            fileType: filetype,
            success: function (res) {
              console.log("打开成功")
            },
            fail: function (res) {
              wx.showToast({title: '打开文档失败', icon: 'none', duration: 2000})
            },
          })
      },
      fail: res => {
        wx.hideLoading();
        console.log(res);
      },
    });
  },