wx.openDocument() 回调成功却无法打开pdf文件。
发布于 6 年前 作者 yang61 13228 次浏览 来自 问答
  • 预期表现

    每次调用可以直接打开pdf

最近的开发重要用到预览pdf 文件的需求,使用了代码如下

wx.showLoading({
          title: 'pdf预览准备中',
        })
        wx.downloadFile({
          url: e.currentTarget.dataset.pdf,
          success(res) {
            console.log(res)
            const filePath = res.tempFilePath
            setTimeout(function() {
              wx.openDocument({
                fileType:"pdf",
                filePath:filePath,
                success:function(res) {
                  console.log(res)
                  wx.hideLoading()
                },
                fail:function(e) {
                  console.log(e)
                }
              })
            }, 300)
          }
        })

上述代码在微信开发者工具中可以顺利运行。

在手机端(安卓)可以运行,其中两次回调皆为success,但是无法打开pdf文件。

IOS端则在使用了更新的基础库(2.7.0)且开启调试之后可以正常使用。

1 回复

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

回到顶部