简体   繁体   中英

How can I prevent a PDF file from being downloaded or printed with PHP or JavaScript?

I am looking for ways to present a PDF file in the browser but make it not downloadable or printable.


If someone really goes through all the trouble to disable the JavaScript library or anything like that, that is fine. This is more for the reason that the content within the PDF will be updated regularly so if you download it it will be out of date by the next day.


I also cannot rely on marking the pdf as protected or encryption as a reasonable way to accomplish this.

If you have any library recommendations or anything else it would be appreciated. I am currently exploring if it is feasible using PDF.js and ViewerJS

I was able to find a solution using ViewerJS and this CSS. The CSS shows a blank page when you try to print (ViewerJS already distorts it to a non-printable state) and ViewerJS prevents you from downloading as a PDF file and instead tries to save as an HTML file.

This meets the requirements of making it just inconvenient enough to discourage users from trying to download the file since the file is always easily accessible on almost any page of the site.

https://gist.github.com/ActuallyConnor/2a80403c7827dd1f78077fb2b5b7e785

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM