PHP to view PDF on web page and disable user to download


I'm going to write a site that lets users to view pdf files but I don't want them to save the files to their own hard drive due to the copy right law. I'm researching how to view it by using PHP, but I have no idea how to disable user not to download the files.

Actually, I want to use JavaScript to disable this action, but I get suggestions from other people not to do so because it's annoying to user.

So any suggestion or help would be very much appreciated.




USE CSSopacity: 1.0 with a<div> positioned over your content...

You could output the pdf using<object> or<iframe>, then place a with absolute position and use z-index to cover your pdf. Use the cssopacity: 1.0.

Now when users try to click or copy, they get nothing because they are really clicking on a blank<div>!!!!

Its a hack, but it works! The user will be able to read the content, they could take a screen shot, but they won't be able to actually copy the text and paste it anywhere.




Method 01

Implementing that useing Google books

<iframe frameborder="0" scrolling="no" class="page_speed_658060490" src="" width="500" height=500>

enter image description here

In above image it showsEmbed that will be the code. And Download or Print option is not available on this. Google dosc can prevent download but its allow toSave 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 onpdf and goto Share(below image)


Then go to Advanced option in left bottom


Tick Both check boxes. After copyembed link and paste it to yoursrc. No download and Save drive option is not allowed

Note: Method 01 and Method 02 is Tested




You can't prevent your visitors from downloading, copying or scrapping anything you're outputting to their browsers. If they can view it they can always screenshot it. Which brings in the optimal solution to your problem: Simply offer image copies of your documents instead of actual PDF files. You can convert / mass convert PDF files to JPEG easily with Photoshop.




I hope I am not very late to reply. But here's is something you can do to prevent the users. Use iFrame to display your PDF and make sure that you are displaying using Google. I used the following code :

 <iframe src="" class="page_speed_1046148704" frameborder="0">

Here you can simply change theurl= and replace it by your own URL where you kept your PDF.




Try this one:

<iframe  src="test1.pdf" scrolling="no" frameborder="0" height="100%" width="100%" class="page_speed_72655846">




try this

<embed src="" width="500" height="500">

People are also looking for solutions to the problem: php - ZF2 - How to use SQL_CALC_FOUND_ROWS in columns()


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.