uniapp 在线预览pdf

本文介绍如何在uniapp项目中实现PDF文件的在线预览功能。通过复制特定文件夹并设置模板与脚本来加载PDF文件,最终实现在安卓平板上的PDF预览。提供了一个具体的示例代码以及相关项目的下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

uniapp项目APP 在线预览pdf

1、将hybrid这个文件夹整个复制到你的项目
在这里插入图片描述

2、先创建一个 pdf页面用于展示pdf文件

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

<script>
    export default {
        data() {
            return {
            pdfUrl:'',
            htmlUrl: '/hybrid/html/web/viewer.html', 
           }
        },
        onLoad(options) {
        //从A页面点击跳转传递pdf文件路径过来
                let fileUrl = encodeURIComponent(options.pdfUrl) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。
                this.pdfUrl= this.htmlUrl+ '?file=' + fileUrl
          }
    }
</script>

2、在A页面点击跳转

 <view class="content-right">
			   <!-- pdf文件预览 -->
			   <view class="pdf-box" >
					<image src="../../static/images/pdf.jpg"  class="pdf-img" @click="showPdf"></image>
				</view>
		 </view>

	//pdf,传入pdf的url 可实现在线预览
			showPdf(){
				   let pdfUrl= encodeURIComponent('http://rtdsoft.xxx.pdf')
				        uni.navigateTo({
						  url:'../pdfWebview/pdfWebview?pdfUrl='+ pdfUrl
				    })
			},

3、效果如下,我是用于安卓平板上。
在这里插入图片描述
本文章的demo下载链接(包含了uniapp app使用websocket的demo):https://gitee.com/ZhouLoveBrother/uniapp-websocket-pdf

关于uniapp websocket的笔记:https://blog.csdn.net/ZhouLoverBrother/article/details/111147571

评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值