1、微信小程序,可以使用微信接口:downloadFile和openDocument

wx.downloadFile({
url: 'http://test.com/testfile.pdf', // 示例 url,实际不存在

success: function (res) {

const filePath = res.tempFilePath

wx.openDocument({
  filePath: filePath,

  success: function (res) {
    console.log('打开文档成功')}  }) }})

如果明确只有微信使用可以考虑,只是如果有浏览直接使用或钉钉之类不行,而且如果后面更换到浏览器或WEBAPP又要更换也挺麻烦的。

2、pfile的文件预览

很简单一句话
window.open('http://www.pfile.com.cn/api/profile/onlinePreview?url='+encodeURIComponent(“文档地址”));

使用了一阵,完美,强烈推荐

3、office online

let url = "https://view.officeapps.live.com/op/view.aspx?src=" + 文档url;

window.open(url); //新建窗口打开链接预览

或者

window.location.href = url; //本页面内跳转链接实现预览

PDF好像要单独处理,用了一下感觉不太爽放弃了


1 声望0 粉丝