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}`)
			// }
		}
	});
},
相关推荐
月巴月巴白勺合鸟月半10 小时前
几种 HTML 转 PDF的方式
pdf·c#
小恒恒1 天前
2025 Vibe Coding 有感
前端·uni-app·trae
夏日白云1 天前
《PDF解析工程实录》第 12 章|别让模型贴着墙走:为什么加一圈空白,效果反而更好?
图像处理·机器学习·pdf·llm·大语言模型·rag·文档解析
一颗小青松1 天前
uniapp使用uni-im
uni-app
2501_916007471 天前
iPhone APP 性能测试怎么做,除了Instruments还有什么工具?
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
Windows 环境下有哪些可用的 iOS 上架工具, iOS 上架工具的使用方式
android·ios·小程序·https·uni-app·iphone·webview
December3101 天前
新手入门指南:PDF页面方向怎么旋转?
pdf·pdf页面旋转·旋转pdf页面方向·pdf旋转
Summer不秃1 天前
使用 SnapDOM + jsPDF 生成高质量 PDF (含多页分页, 附源码)
前端·javascript·vue.js·pdf·node.js
bosins1 天前
基于Python实现PDF文件个人隐私信息检查
开发语言·python·pdf
bosins1 天前
基于Python开发PDF文件元数据查看器
开发语言·python·pdf