You are here:

DHTML/animated GIF for a PDF download

Advertisement


Question
Hi

My question is that I have a free PDF ebook on my website that is 1.8 MB in size and it takes a few seconds to load in the browser. Right now I have a .jpg download button with a link to my PDF download.  Here is my website link.. http://shenreed.com/index.html  and Book 1 is the large PDF

What I would like to do is two things....

1) To be able to show a animated “loading” GIF on the white browser page as the PDF loads so that people know that it’s loading and for it to stop when the page has loaded.

2) Have the option to have direct download pop up, instead of having to go through clicking on “file” and then “save as” routine.

I’ve tried searching the web for an answer but I’m lost with all the different coding. I am somewhat familiar with html and a bit of CSS code and the odd self contained java script as I did build my website. These features would just make things a little more user friendly. Any help would be appreciated,

Regards
John


Answer
John,

1) Cannot be done.  The white browser page is actually the PDF--there's unfortunately nowhere to put a loading image.  There's no workaround for this.

2) Although this question is out of the scope of DHTML, I can point you to an answer in PHP.

<?php
header('Content-Type: application/save');
header('Content-Disposition: attachment; filename=filename.pdf');
readfile(http://www.site.com/filename.pdf);
?>

You would put this at the very top of your php page.  That means, your index.html page would need to be index.php for the above lines to work. Hopefully, your web host provides PHP support.  If you don't find success using this method, try searching for answers in the PHP section of this site or elsewhere on a PHP forum.

- Andrew  

DHTML

All Answers


Answers by Expert:


Ask Experts

Volunteer


Andrew Hoffman

Expertise

Ask me about JavaScript, CSS, HTML5/XHTML, or PHP. Chances are I'll be able to help you. I know the economy is in the tank, but if you like my answer, please consider donating a few bucks. It's like tipping your barista, if your barista served fresh code instead of coffee.

Experience

I started doing this when boy bands were still cool.

Education/Credentials
I read a lot of nerdy books to get here.

©2012 About.com, a part of The New York Times Company. All rights reserved.