概述
支持PDF查看
支持PDF目录
支持PDF跳转页码
支持PDF横竖屏切换
支持PDF试看付费VIP回调、带弹窗、支持自定义文案
如何调用插件
const pluginModule = uni.requireNativePlugin('yuange-YGPDFReadModule');
网络在线查看PDF
onLineReadPDF() { let that = this; uni.showLoading({ title: '请稍候...' }); //网络地址,选调用下载方法下载到本地,再调用插件显示 uni.downloadFile({ url: '网络PDF测试地址', success: function(res) { var filePath = res.tempFilePath; let realFilePath = plus.io.convertLocalFileSystemURL(filePath); pluginModule.callNativePDFRead( { inFilePath: realFilePath, //目录 catalogue: [{ title: '章节一', page: 0, titleLevel: 1 //titleLevel用于标题缩进,值越大,越向右缩进,可用于标识标题类别 }, { title: '第1小节', page: 0, titleLevel: 2 }, { title: '第2小节', page: 0, titleLevel: 2 }, { title: '章节二', page: 1, titleLevel: 1 }, { title: '第1小节', page: 1, titleLevel: 2 }, { title: '第2小节', page: 1, titleLevel: 2 }, { title: '第3小节', page: 1, titleLevel: 2 }, { title: '章节三', page: 2, titleLevel: 1 }, { title: '第1小节', page: 2, titleLevel: 2 }, { title: '第2小节', page: 3, titleLevel: 2 }, { title: '第3小节', page: 4, titleLevel: 2 }, { title: '章节四', page: 5, titleLevel: 1 }, { title: '章节五', page: 5, titleLevel: 1 }, { title: '结尾', page: 22, titleLevel: 1 } ] }, result => {} ); }, complete: function() { uni.hideLoading(); } }); }
试看PDF付费VIP会员(网络PDF可通过uni.downloadFile下载本地后打开)
tryReadPDFVip() { let that = this; pluginModule.callNativePDFRead({ inFilePath: '本地绝对路径PDF测试地址', catalogue: [ { title: '章节一', page: 0, titleLevel: 1 }, { title: '第1小节', page: 0, titleLevel: 2 }, { title: '第2小节', page: 0, titleLevel: 2 }, { title: '章节二', page: 1, titleLevel: 1 }, { title: '第1小节', page: 1, titleLevel: 2 }, { title: '第2小节', page: 1, titleLevel: 2 }, { title: '第3小节', page: 1, titleLevel: 2 }, { title: '章节三', page: 2, titleLevel: 1 }, { title: '第1小节', page: 2, titleLevel: 2 }, { title: '第2小节', page: 3, titleLevel: 2 }, { title: '第3小节', page: 4, titleLevel: 2 }, { title: '章节四', page: 5, titleLevel: 1 }, { title: '章节五', page: 5, titleLevel: 1 }, { title: '结尾', page: 22, titleLevel: 1 } ], isVip: true, //是否有vip限制 isShowVipDialog: true ,//是否显示VIP购买提示弹窗 pageRange: [0, 2], //只允许查看的页数 totalPage: 15 ,//PDF总页数 pdfBottomVipTitle:'亲,试看结束,只有VIP会员才能继续观看哦', vipDiloagTitle:'温馨提示', vipDiloagContent:'亲,您还不是VIP会员,需要购买吗?', vipButtonCancel:'取消', vipButtonConfirm:'去购买' }, res => { that.result = JSON.stringify(res) if (res.code == 3) { //这里是回调,处理您的业务逻辑 uni.showToast({ title: "亲,这个是VIP购买回调哦", icon: "none" }) } } ); }
演示
Demo下载链接: https://pan.baidu.com/s/1ePL4ghY8P9Ge9-VqyaMgRQ 提取码:hrqw
有需要定制插件和咨询问题的可以联系QQ 2729404527
评论