uniapp PDF文件预览/打开

兼容微信小程序/h5/ios/android

在微信小程序环境下需要配置pdf域名

javascript 复制代码
pdfPreview(url){
	var title = '预览'
	uni.showLoading({ title: '加载中', mask: true })
	//由于android 下webview无法直接打开pdf,需要先下载
	uni.getSystemInfo({
		success: res => {
			console.log(res.platform);
			// if (res.platform === 'android') {
				wx.downloadFile({
					url: url,
					// filePath: wx.env.USER_DATA_PATH  + "/我的协议.pdf",
					success: function(res) {
						const filePath = res.tempFilePath;
						uni.showLoading({ title: '正在打开', mask: true })
						wx.openDocument({
							filePath: filePath,
							showMenu: true, // 显示右上角菜单
							fileType: "pdf",
							success: function(res) {
								uni.hideLoading()
								console.log('打开文档成功');
							},
							fail: function(err) {
								uni.hideLoading()
								console.log('fail:' + JSON.stringify(err));
							}
						});
					}
				});
			// } else {
			// 	this.$tab.navigateTo(`/pagesA/common/webview/index?title=${title}&url=${url}`)
			// }
		}
	});
},
相关推荐
码间留白1 天前
uni-app 鸿蒙离线打包:一个改动从源码到真机要穿过几条链
uni-app·鸿蒙·deveco·离线打包·uts插件
多客:duokelijie2 天前
代练订单系统选型思路:跨品类游戏接入、订单分层管理、自动结算逻辑拆解!
数据库·mysql·微信小程序·前端框架·uni-app·php·持续部署
码间留白2 天前
鸿蒙端对接 BLE 血压计:从一次握手到读数入库(二)设备篇
物联网·uni-app·鸿蒙·蓝牙ble·血压计
华玥作者3 天前
Vue 3 + TypeScript + uni-app 组件库推荐:hy-app(华玥组件库)
vue.js·typescript·uni-app
FinelyYang3 天前
uniapp使用kkfileview在线预览ppt,excel,word,pdf类型文件
pdf·uni-app·powerpoint
2501_916008893 天前
iPhone 设备信息查看,用 KeyMob 看型号、序列号、电池健康和 UDID
android·ios·小程序·https·uni-app·iphone·webview
WORLDPO92264 天前
QTE-020-01-L/F/C-D-A-K-TR_实物_数据手册PDF_国产替代
pdf
ModyQyW4 天前
vite-plugin-uni-manifest 0.7:在 uni-app 读取之前生成
前端·uni-app
lyz2468594 天前
uniapp vue3 小程序开发注意事项
uni-app
asdzx674 天前
C# 操作 PDF 元数据:从属性写入到字段提取的完整流程
前端·pdf·c#