使用openDocument方法,新开页面打开文档,文档右上角有保存本地按钮,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx我们以uniapp为例:
uni.downloadFile({ url: "https://example.com/test.pdf", // 替换为你的PDF文件URL success: function(res) { const filePath = res.tempFilePath; const fileType = that.result.data.text.split('.').pop().toLowerCase(); const Extensions = ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx']; if (Extensions.includes(fileType)) { uni.openDocument({ filePath: filePath, showMenu: true, success: function(res) { console.log('打开文档成功'); } }) } })
网友回复