微信小程序直接预览PDF文件
官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/wx.openDocument.html
代码:
//打开pdf文件
wx.showLoading({
title: '加载中...',
})
wx.downloadFile({
url: pdf_url,
success: function (res) {
console.log('downloadFile', res);
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log(res);
console.log('打开文档成功')
wx.hideLoading()
},
fail: function (res) {
console.log('打开失败')
},
})
}
})