uniapp之安卓端pdf預覽

uniapp之安卓端pdf預覽

原理:

將文件下載到本地,使用uni api預覽文件

exportPDF() {
					uni.downloadFile({
						url: "http://192.168.1.237:9000/profile/statute/937820.pdf",
						success: res => {
							console.log(res)
							if (res.statusCode === 200) {
								// 保存pdf文件至手機,一般安卓端存儲路徑爲:手機存儲/dcim/camera文件夾下
								uni.saveFile({
									tempFilePath: res.tempFilePath,
									success: function() {
										uni.showToast({
											title: "文件已保存至/DCIM/CAMERA文件夾下",
											icon: "none"
										})
										setTimeout(function() {
											// 預覽pdf文件
											uni.openDocument({
												filePath: res.tempFilePath,
												showMenu: true,
												success: function(file) {
													console.log("file-success",
														file)
												}
											})
										}, 1500)
									},
									fail: function() {
										uni.showToast({
											title: "保存失敗,請稍後重試!",
											icon: "none"
										})
									}
								})
							}
						}
					})
				}

  直接調用即可。

註釋:測試過pdfjs-3.5.141-dist、pdfjs-2.16.105-dist可在瀏覽器正常使用,真機可以看到頁面打不開pdf文件。

 

 

鑽研不易,轉載請註明出處。。。。。。

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章