下载PDF.js
问题描述
在uniapp中预览base64的PDF,可以使用web-view组件嵌入一个PDF.js的实例。以下是一个简单的示例:
解决方案:
1.在页面的.vue
文件中添加web-view组件:
<template><view style="width: 50%;"><web-view :src="allUrl"></web-view></view>
</template><script>export default {data () {return {allUrl: '',viewerUrl: '/static/hybrid/html/web/viewer.html',//引入下载好的文件// pdfUrl: 'http://172.11.11.11:8888/ceshi.pdf',//可访问的http地址'pdfUrl':'data:application/pdf;base64'// 可以去线上生成一个base64pdf}},onLoad (options) {this.pdfUrl = options.pdfUrllet fileUrl = encodeURIComponent(this.pdfUrl) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。this.allUrl = this.viewerUrl + '?file=' + fileUrl}}
</script><style></style>