Embed Pdf on a Webpage and Prevent Download

Embed PDF on a webpage and prevent download

2017 Note: this feature has moved locations and the implementation has changed since it was originally answered.


Google Viewer offers a solution.

Use the iframe it generates for you.

How do I make a PDF link in HTML non-downloadable?

Making a PDF non-downloadable is as simple as adding #toolbar=0 to the URL.

To embed a PDF in your site:

<iframe src="doc.pdf#toolbar=0" width="100%" height="500px"></iframe>

To open the PDF in a new tab:

<a href="doc.pdf#toolbar=0">PDF</a>

WARNING: This is not a DRM solution, a sophisticated user could still download the file from the server.

Recommended way to embed PDF in HTML?

Probably the best approach is to use the PDF.JS library. It's a pure HTML5/JavaScript renderer for PDF documents without any third-party plugins.

Online demo:
https://mozilla.github.io/pdf.js/web/viewer.html

GitHub:
https://github.com/mozilla/pdf.js

Prevent PDF file from downloading and printing

Ultimately you will need to:

  • Create Images for each page
  • Present those to the user on the web via your own interface (html, flash etc)

Keep in mind flash wont work on Apple devices if that's required.

A print screen will allow someone to recreate the low res image you present, and in this case you could add a watermark to the image.

Embed PDF while Removing Print / Save / Etc. .

After 8+ hours of trying many different approaches to the problem we ended up going with a paid option of Scribd which works in all browsers and looks decent enough for us to use. That is our solution.

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

View a PDF file in HTML not to download it

2018 Update

Almost all modern browsers have built-in PDF viewers. You can directly link to the PDF file and the browser will view it. You can also use an <iframe> if you want to view it inside an HTML page (e.g. with your website headers, etc.).

Another approach, but more complicated and not necessary except for very special circumstances, is to convert the PDF files to HTML (as described in #1 of the 2012 answer below).

Original Answer (Outdated, from 2012)

Viewing the PDF file in the browser (without download) requires an add-on to the client's browser. Google Chrome, for example, has a built-in PDF viewer and can open files directly, while IE and Firefox require that you install a plug-in (the one that comes with Adobe Reader).

There are two other approaches:

  1. Convert the file to HTML, image, or any other format that can be directly viewed in the browser. This conversion can be on-the-fly using a server-side (written in PHP, Python, ASP, whatever language), or you can just pre-convert all files to a readable one.

  2. The other approach, which is the best, is to use a Flash-based PDF viewer (such as http://flexpaper.devaldi.com/). This is easy, flexible and doesn't require writing server-side code. This approach is used by many Document-sharing sites (e.g. http://www.scribd.com/, http://www.slideshare.net/, http://www.docstoc.com/)

Prevent (the average user) from downloading PDF

While I agree with the answers about the requirements being idiotic, there are ways around your problem. Namely, simply don't give the average user a PDF, but something else. And give the PDF to the privileged users. You already pointed out you have a way of telling them apart.

There are libraries you can use to convert from PDF to another format. I was once given a relatively similar assignment. Mine was to give a preview of a document before the user DL'd it and the client app opened the relevant word processing software.

While I can't in good conscience recommend Aspose libraries (I really didn't like working with this tool), they were what was in use in the company I worked for at the time, and I know they can do what you need to do. They are neither free as in free-speech, nor free as in free-beer, but they can be downloaded and tried free of charge, at the cost of a big watermark on the generated/converted documents.

I let Aspose do the work of converting the document to an HTML file, and loaded it in an iFrame in my interface.

If the solution of serving the PDF's contents in another format is not acceptable to your manager, you really need to let them know of their idiocy.



Related Topics



Leave a reply



Submit