uniapp里在h5端,app端在线预览PDF文件

一,pdf.js下载地址https://sourceforge.net/projects/pdf-js.mirror/files/ 

下载版本太高,需要node版本达到22.0,否则会报Promise.withResolvers is not a function

二,将下载好的包解压并放到static目录里的pdfview中

三,找到web里的viewer.mjs文件,隐藏框里内容,不然会报file origin does not match viewer's错误

四,新建一个webView.vue文件

<template>
	 <view style="width: 100%;height: 100%;">
	        <web-view :src="webUrl"></web-view>
	    </view>
</template>

<script>
		 export default {
			 data(){
				 return{
					 webUrl:null,
					 pdfViewUrl: '/static/pdfview/web/viewer.html'
				 }
			 },
			 onLoad(options){
				 if(options.url){
					 this.webUrl = decodeURI(options.url)
					 this.webUrl = this.pdfViewUrl + '?file=' + encodeURI(this.webUrl)
				 }
			 }
             //https://view.officeapps.live.com/op/view.aspx?src=""
             //options.url是上一个页面传过来的pdf文件
		} 
</script>

<style>
</style>

效果预览

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值