DHTML/animated GIF for a PDF download
Expert: Andrew Hoffman - 3/9/2009
QuestionHi
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
AnswerJohn,
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