公司最近有一个需求需要在小程序中查看政策并下载打开PDF附件,这里博主给大家总结了方法如下,主要用到了微信小程序的wx.downloadFile和wx.openDocument方法:文章来源地址https://www.toymoban.com/news/detail-505552.html
//下载PDF文件
function downLoadPDF(){
wx.showModal({
title: '提示',
content: '确认要打开此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
文章来源:https://www.toymoban.com/news/detail-505552.html
到了这里,关于微信小程序下载、打开及预览PDF文件的方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!