如何在支付宝小程序中预览PDF文件

追格官方小助手/ 2022年05月20日/ 小程序/ 浏览 3746

支付宝小程序提供了my.openDocument接口,即在新页面打开文件预览的 API,根据支付宝小程序文档提示,暂时只支持预览 PDF 格式文件。


js示例代码,代码来自支付宝小程序文档:https://opendocs.alipay.com/mini/api/mwpprc


// .js
my.downloadFile({
  // 示例 url,并非真实存在
      url: 'http://documentExample.com/alipay.pdf',
      success({ apFilePath }) {
        my.hideLoading();
        my.openDocument({
          filePath: apFilePath,
          fileType: 'pdf',
          success: (res) => {
            console.log('open document success')
            }
          })
        }
      })


发表评论

暂无评论,抢个沙发...

客服 工单