How To Make PDF A Downloadable File?

12 replies
  • WEB DESIGN
  • |
I am having an issue when I put the file on my site that when I link to it, that it opens the PDF to be read. What I am looking for is a way so that when I link to the file, that it brings up the prompt asking for the person to download the file.

It is a Wordpress site and I am using a non zipped PDF. Any help is very much appreciated.
#downloadable #file #make #pdf
  • Profile picture of the author jpweb
    You can do this one of 2 ways. In PHP or in your .htaccess file.

    In PHP you need to Set Content-Disposition. Use this code
    PHP Code:
    header('Content-Disposition: attachment; filename="yourfile.pdf"'); 
    You can also edit your .htaccess file to include the following
    Code:
    AddType application/octet-stream .pdf
    {{ DiscussionBoard.errors[8953378].message }}
    • Profile picture of the author Breakinglink
      Oh Geez, I am sure these are simple matters but could you give me a hint as to which is easier for a novice? I am going to have to watch a video or something on how this is accomplished.
      Signature

      "Someday" is a disease that will take your dreams to the grave with you.


      Dost thou love life? Then do not squander time, for that's the stuff life is made of. -Ben Franklin

      {{ DiscussionBoard.errors[8953405].message }}
  • Profile picture of the author Istvan Horvath
    For a novice the easiest is to zip it in a .zip file - those start to download automatically
    Signature

    {{ DiscussionBoard.errors[8953410].message }}
    • Profile picture of the author Breakinglink
      Originally Posted by Istvan Horvath View Post

      For a novice the easiest is to zip it in a .zip file - those start to download automatically
      That was my original idea but I was afraid my target audience be hindered by this. Are either of the solutions listed above relatively easy to accomplish? I don't mind digging to get the work done but a friendly nudge in the right direction is always appreciated.
      Signature

      "Someday" is a disease that will take your dreams to the grave with you.


      Dost thou love life? Then do not squander time, for that's the stuff life is made of. -Ben Franklin

      {{ DiscussionBoard.errors[8953421].message }}
      • Profile picture of the author jpweb
        Adding a single line to your .htaccess file is extremely easy. You can FTP into your server and download the .htaccess file open in in Notepad and add the line, you can login to cPanel and use the file manager and edit the file there as well.
        {{ DiscussionBoard.errors[8953426].message }}
        • Profile picture of the author Breakinglink
          A little intimidated when I checked it out a moment ago. I added a plug in called Bullet Proof Security and it added lines to my .htaccess file and I am not sure what I can mess with and what I can't. Just saving and keeping a unaltered file to upload over any goof ups should keep me in the clear, yea?
          Signature

          "Someday" is a disease that will take your dreams to the grave with you.


          Dost thou love life? Then do not squander time, for that's the stuff life is made of. -Ben Franklin

          {{ DiscussionBoard.errors[8953434].message }}
          • Profile picture of the author jpweb
            Yes save a copy somewhere safe, If there's no where the depicts start and end points in the file (for different plug-ins) you can just add it to the last line.
            {{ DiscussionBoard.errors[8953436].message }}
  • Profile picture of the author Breakinglink
    Added the line and saved. However opening the file from a link still just opens a PDF file. I copied the code as you had it. Does the code need the file name before the .PDF? I am sure I am making a small goof but all my other fixes don't seem to be panning out.
    Signature

    "Someday" is a disease that will take your dreams to the grave with you.


    Dost thou love life? Then do not squander time, for that's the stuff life is made of. -Ben Franklin

    {{ DiscussionBoard.errors[8953530].message }}
  • Profile picture of the author jpweb
    If that didn't work with your server configuration try adding this block instead

    Code:
    <FilesMatch ".(pdf|PDF)">
        ForceType application/pdf
        Header set Content-Disposition attachment
    </FilesMatch>
    {{ DiscussionBoard.errors[8953535].message }}
    • Profile picture of the author jpweb
      And if the above doesn't work with your server, the final option that I know of is this.

      Code:
      <FilesMatch ".(?i:pdf)$">
       ForceType application/octet-stream
       Header set Content-Disposition attachment
      </FilesMatch>
      {{ DiscussionBoard.errors[8953539].message }}
    • Profile picture of the author Breakinglink
      JP, when that prompt popped up, I could have kissed you. Thanks a ton for helping a newbie out.
      Signature

      "Someday" is a disease that will take your dreams to the grave with you.


      Dost thou love life? Then do not squander time, for that's the stuff life is made of. -Ben Franklin

      {{ DiscussionBoard.errors[8953557].message }}
      • Profile picture of the author jpweb
        No problem. Glad I could help!
        Originally Posted by Breakinglink View Post

        JP, when that prompt popped up, I could have kissed you. Thanks a ton for helping a newbie out.
        {{ DiscussionBoard.errors[8953572].message }}

Trending Topics