How to Restrict User from Downloading or Saving Pdf File

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.

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 to Prevent PDF Document from Being download to users PC?

One option is to render the PDF to JPEG or some other image format and only serve the rendered images to the user. Some of the PDF libraries allow you to render PDF's to other file formats.

Another option may be to send/redirect the PDF through to an online PDF viewing app in the same way Google does with attachments in GMail. That way the user sees a JPEG of the PDF and cannot download the PDF.

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

How to prevent users from downloading source code files using the PHP download option I have for downloading pdf files in my web application?

You've fallen fowl of a pretty bad design decision here that makes you vulnerable to file system traversal.

You might consider:

  1. Ensure the requested file ends in .pdf
  2. Ensure that the file being read ends in .pdf
  3. Drop any requests where the file parameter contains ..

Given Download.php doens't look to be ensuring requesters are authenticated at all, I would suggest maybe having your PDF documents live within a web accessible directory and just linking directly to them, instead of creating an attack vector that could compromise your server.



Related Topics



Leave a reply



Submit