View PDF Only - NOT Download?

Discussion in 'Pre-Sales Questions' started by gracefulonline, Dec 29, 2015.

  1. gracefulonline

    gracefulonline New Member

    Joined:
    Dec 29, 2015
    Messages:
    1
    Is there a way to view a premium PDF file, instead of it being able to download? We do not want our members to be able to download, print, or save the PDF File. Instead we just want it to open up in their browser to view. How can this be accomplished?

    Thank you.
  2. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    You will need to use a script to send the pdf inline, please be aware that even if you say it is inline the user is still able to save it using the browser. Also, it will only be viewable if the browser has the pdf plugin installed (not all browsers have it as default).

    PHP:
    <?php
    $file 
    './path/to/the.pdf';
    $filename 'Custom file name for the.pdf'/* Note: Always use .pdf at the end. */

    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="' $filename '"');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' filesize($file));
    header('Accept-Ranges: bytes');

    @
    readfile($file);
    That should work, not tested though .. from stackoverflow was too lazy to type it myself ;-)
  3. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    The above supplied script is basically the same as I use on my site for downloading PDF files.

    It will, depending on browser settings, offer the choice of opening or saving the file so will not accomplish what original poster was looking to do.
  4. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    As I think I said ... forcing display only of anything with the intention of not allowing a copy is not really reliable. If it is displayed it is available to copy, ie drag it from the cache and save it if you want to put the effort in.
  5. robw

    robw CGI-Central Partner

    Joined:
    Dec 18, 2007
    Messages:
    287
    In short - NO, it is not possible... Anything that can be viewed can be printed/downloaded.

    You can make it harder - e.g. by storing files publicly in Google Drive and ticking to 'prevent downloading' but nothing can stop printing of information (e.g. by printing screen)

    Cheers
    Rob
    Last edited: Jan 2, 2016

Share This Page