微信小程序打開PDF格式文件的方法
wx.downloadFile({
url: 'http://**.*****.***/reshaiwai/demo.pdf', //要預覽的PDF的地址
success: function (res) {
console.log(res);
if (res.statusCode === 200) { //成功
var Path = res.tempFilePath //返回的文件臨時地址,用於后面打開本地預覽所用
wx.openDocument({
filePath: Path, //要打開的文件路徑
success: function (res) {
console.log('打開PDF成功');
}
})
}
},
fail: function (res) {
console.log(res); //失敗
}
})