微信小程序本身不支持屏蔽下载按钮加载在线pdf。因此,需要通过其它方式进行加载。
在这里,使用当前最新版的pdf.js 3.0+,点击跳转至下载地址
1、修改View.html
下载后,可以屏蔽下载按钮,修改view.html如下:
浏览
Current View
2、修改view.js
如果需要修改以文件名做为页面的Title,需要修改view.js,屏蔽掉设置document.title的代码
3、在Nginx中发布该程序以及相应的pdf文件
设置nginx.conf:
server {listen 2000;listen [::]:2000;server_name _;root /home/data/file-db;index /html/web/viewer.html;location / { autoindex off;autoindex_exact_size off;autoindex_localtime off;}}
把pdf文件放置在 /home/data/file-db中(含子目录)
把pdf.js相关的web和build文件夹放在/home/data/file-db/html中。
使用地址:http://<>:2000/html/web/viewer.html?file=http%3A%2F%2F171.84.0.40%3A2000%2Fstandard%2Fpolicy%2F10267ad6-2c0a-4056-b97a-6b158cf55698.pdf
“?”后的部分为encodeURIcomponent()后的url,端口号需要与本服务url相同
4、小程序中使用该服务