viewPdf(item){
var that = this
var pdfUrl = item.pdfUrl;
var filename = item.feature;
var ext = pdfUrl.substring(pdfUrl.lastIndexOf('.') + 1)
wx.showLoading({
title:'加载中',
mask:true
})
wx.downloadFile({
url: pdfUrl, //.pdf文件地址或者可以在浏览器直接下载pdf的地址
filePath: wx.env.USER_DATA_PATH + '/' + filename+'.'+ext,
success: function (res) {
let Path = res.filePath; //返回的文件临时地址,用于后面打开本地预览所用
wx.openDocument({
filePath: Path,
fileType:'pdf',// 加上你需要打开的类型不然有些机型打不开报错
showMenu: true,
success: function (res) {
wx.hideLoading();
console.log('打开文档成功')
},
fail: function (res) {
wx.hideLoading();
console.log(res);
},
})
},
fail:function (res){
console.log(res)
}
})
},
网友评论