微信小程序pdf文件的三種展示方式


1、pdfjs第三方

  內嵌web view

<web-view src="https://byfile.disscode.cn/pdfjs-2.8/web/viewer.html?file={{url}}"></web-view>

2、微信小程序自帶方式

  通過wx.downloadFile下載pdf文件,再通過wx.openDocument展示。

toViewWx: function (e) {
    wx.downloadFile({
        url: e.currentTarget.dataset.url,//可以是后台傳過來的路徑
        success: function(res) {
            const filePath = res.tempFilePath
            wx.openDocument({
                filePath: filePath,
                success: function(res) {
                    //成功
                }
            })
        }
    })
  },

3、markdown第三方

  同樣是內嵌web view

<web-view src="https://byfile.disscode.cn/marked/marked.html?file={{url}}"></web-view>

第三種方式與第一種方式雷同。都可以使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM