Php to View Pdf on Web Page and Disable User to Download

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>

enter image description here

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

02

Method 02

Using Google Drive

Right click on pdf and goto Share(below image)

03

Then go to Advanced option in left bottom

05

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



Leave a reply



Submit