公司最近有一個需求需要在小程序中查看政策并下載打開PDF附件,這里博主給大家總結(jié)了方法如下,主要用到了微信小程序的wx.downloadFile和wx.openDocument方法:文章來源地址http://www.zghlxwxcb.cn/news/detail-505552.html
//下載PDF文件
function downLoadPDF(){
wx.showModal({
title: '提示',
content: '確認(rèn)要打開此PDF政策文件嗎?',
showCancel: true,
cancelText: '取消',
confirmText: '確定',
success: (result) => {
if (result.confirm) {
wx.downloadFile({
url: 'https://********/file/preview/XG-2019-01.pdf', //示例的url地址
success: function (resinfo) {
let path = resinfo.tempFilePath;
console.log(path, resinfo)
wx.openDocument({
filePath: path,
fileType: 'pdf',
success: function (rest) {
co
文章來源:http://www.zghlxwxcb.cn/news/detail-505552.html
到了這里,關(guān)于微信小程序下載、打開及預(yù)覽PDF文件的方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!