PHP to view PDF on web page and disable user to download
Method 01
Implementing that useing Google books
<iframe frameborder="0" scrolling="no" style="border:0px" src="https://books.google.com.kh/books?id=e5MkzETNcsgC&lpg=PP1&dq=typography&pg=PA11&output=embed" width="500" height=500>
</iframe>
In above image it shows Embed
that will be the code. And Download or Print option is not available on this. Google dosc can prevent download but its allow to Save to Drive
option. Then in drive i can download it. But Google books not allow any of that.
in view
Method 02
Using Google Drive
Right click on pdf
and goto Share(below image)
Then go to Advanced option in left bottom
Tick Both check boxes. After copy embed
link and paste it to your src
. No download and Save drive option is not allowed
Note: Method 01 and Method 02 is Tested
restrict to download the pdf files
That is not possible. As Jamie said, reading is downloading. When a user is reading a file, browser is downloading that file to temp. So even if you disable the download button, the user can click "File -> Save As" or copy that file from temp folder.
A solution is to give only a sample (first few pages, for example) to the public, and to access the full, they need to signup. I have no better solution in mind that to manually keep 2 files in the server - full and abstract.
How can I prevent a PDF file from being downloaded or printed with PHP or JavaScript?
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
View pdf file in browser instead of downloading
You need to change the Content-disposition
to inline
.
Change
header("Content-disposition: attachment;
filename=".basename('theme/assets/pdf/ci.pdf'));
To:
header("Content-disposition: inline;
filename=".basename('theme/assets/pdf/ci.pdf'));
Related Topics
Reading Numbers as Text Format With Phpexcel
How to Prevent a User from Directly Accessing My HTML Page by Writing Url
Codeigniter Cors Policy: No 'Access-Control-Allow-Origin' Error How to Resolve
Regex: Number Range Excluding Specific Number
How to Store .Pdf Files into MySQL as Blobs Using PHP
Internal Server Error While Run Laravel on Localhost
Windows 10 Docker:/Usr/Bin/Env: 'Php\R': No Such File or Directory
How to Deal With MySQLi Problems - MySQLi_Fetch_Array(): Argument #1 Must Be of Type MySQLi_Result
Project Links Do Not Work on Wamp Server
How to Get Time Difference in Minutes in PHP
How to Get the Sucess Message in the Same Page After Submitting the Contact Form
Removing Specific Elements from Json Encoded Array by Use of PHP
How to Submit Multiple PHP Forms While Each Form Has Its Own Submit Button
Nginx Error Recv() Failed (104: Connection Reset by Peer)
Laravel App Storage Images Failed to Load and Redirect to 404