当前位置:网站首页>JS disable the browser PDF printing and downloading functions (pdf.js disable the printing and downloading functions)
JS disable the browser PDF printing and downloading functions (pdf.js disable the printing and downloading functions)
2022-06-25 21:36:00 【Xiaozai's Valley rain】
The front-end implementation pdf Preview method
(1) use iframe label src=" File address " You can open it directly , You can also set width,height Equal attribute . Specific reference iframe attribute .
<iframe src="http://localhost:8080/%E9%9F%A6%E6%88%90%E7%8E%89.pdf"></iframe> (2) direct a label src=" File address "
<a href=" File address "></a>(3) Using Microsoft's methods Microsoft official documents ( It is not recommended to use if there are defects )
(4) The use of plug-in
vue in Realization pdf preview
above 1,2,3 You can use , but 1,2,3 It uses Browser's own pdf Preview function , The styles are not uniform , If you mind Just Using plug-ins .
4 The plug-in has vue-pdf、pdf.js etc. .
react in Realization pdf preview
above 1,2,3 You can use , but 1,2,3 It uses Browser's own pdf Preview function , The styles are not uniform , If you mind Just Using plug-ins .
4 The plug-in has react-pdf、pdf.js、react-file-viewer etc. .
Ban pdf Printing function
Use the plug-in api
pdf.js Ban
Other plug-ins Be the same in essentials while differing in minor points , You can do it yourself Check information .
use js Ban
In fact, this is not forbidden , It's just hold Button And icons Hide the .
1. With Google Chrome comes with an example
The quick way to open it is Drag the pdf Go to browser You can see it in the library .

Ideas : Namely use js Hide downloaded Icon
Get Icon Give it hide
This step looks like Simple however I started I've tried many times but I can't , because involves shadow-root
The screenshot is as follows :

Review element Will find dom By shadow-root The parcel , therefore Get elements You can't use conventional document Method , Need to use shadowRoot.
let c = document.querySelector("#viewer").shadowRoot.querySelector("#toolbar").shadowRoot.querySelector("#print");
c.remove();Run this code Will find The printed icon disappeared , If you download it, you should also disappear Just use the same method .

Get... Quickly Want elements js Code tricks :
1. Selected elements then Right mouse click
2. choice copy Inside copy js path that will do

Copy js path Copy js route Quickly generate obtain The dom Of js Code ( Very practical )
The effect is as follows :
Like want to download The icon also disappears According to the above step I can get it . then Can Add remove perhaps Modify the style , Any modification is OK .
document.querySelector("#viewer").shadowRoot.querySelector("#toolbar").shadowRoot.querySelector("#downloads").shadowRoot.querySelector("#download");2. edge Also almost
edge All are The operation steps in Chinese are the same as above
1. Selected elements then Right mouse click
2. choice Copy Inside Copy js route that will do

Removal effect as follows :

summary :
I This is just Hide the , You can get the element next expand such as : Change icon , Modify the style wait .
边栏推荐
- couldn‘t be accessed by user ‘_ apt‘
- org. apache. ibatis. exceptions. PersistenceException:
- Working principle and experimental analysis of DHCP
- The correct way to clear the cache of the computer. The computer will not get stuck immediately after changing. practical
- multiplication table
- Win11开始菜单右键空白?Win11开始菜单右键没反应解决方法
- Molecular dynamics - basic characteristics of molecular force field
- JS__ Prototype, prototype chain, call/apply__ Duyi
- PHP Chinese word segmentation API, Harbin Institute of technology ltpcloud, naturallanguageprocessing, free, best practices!
- Send a more awesome website, which can convert curl commands into code in any language
猜你喜欢
![[nailing - scenario capability package] nailer card](/img/ec/c2f342a54ab69d8b834a8a1c8f8a01.jpg)
[nailing - scenario capability package] nailer card

“No bean named ‘UserController‘ available“

智云健康上市在即:长期亏损,美年健康俞熔已退出,未来难言乐观

STM32 self balancing robot project, with code, circuit diagram and other data attached at the end (learning materials and learning group at the end)

Volatile qualifier

What is DNS (domain name server)? (Powercert animated videos)

XMIND to excel test case
![[nail scenario capability package] hospital visitor verification](/img/0e/43433ca5586c48d01708e5fa39a808.jpg)
[nail scenario capability package] hospital visitor verification

PHP Chinese word segmentation API, Harbin Institute of technology ltpcloud, naturallanguageprocessing, free, best practices!

PHP runtime and memory consumption statistics code
随机推荐
Win11录屏数据保存在哪里?Win11录屏数据保存的位置
Simulate ATM system (account opening, login, account query, withdrawal, deposit, transfer, password modification, account cancellation)
109 practical shell scripts
熊市指南|一些本质的教训与具体的生存法则
Pat 1083 list grades (25 points)
Virtualenvwrapper solves the installation error, and virtualenvwrapper is permanently effective
Set eye color
Modprobe: fatal: module kvmgt not found, kvmgt has no module, kvmgt has no driver, gvt-g precautions, gvt-g precautions for starting win10 in UEFI mode
Local Yum source production
Php7.4 arm environment compilation and installation error invalid 'ASM': invalid operate prefix '%c'
Writing manuals using markdown
Illustration tcp/ip - Chapter 1 and 2 Notes
JS__ Inheritance mode, namespace, object enumeration__ Duyi
Is it safe to fry stocks with compass or securities software? Where can I open an account and how
What is a ZFS file system
The latest (2022-2-16) vulnerability of WordPress plug-in bee collection (XSS, WordPress user name exposure, arbitrary article publishing) is repeated
Windows11 windows security center cannot open Windows Defender cannot open
Win11开始菜单右键空白?Win11开始菜单右键没反应解决方法
On dynamic programming
[nailing scenario capability package] company / Park Digital canteen