Click to See Complete Forum and Search --> : pdf link to download file


peteyb
08-16-2006, 07:24 AM
I have a PDF document on my site that i wish users to be able to download by selelcting either a link or a button.

I understand that the user could click a link to open the page then press save but i wish to make their lives that little bit more easier by having a download/save button.

How can i achieve this?

Coulix
08-16-2006, 07:52 AM
<a href="pdf_document.pdf">Rightclick this link and select "save as".</a>
Replace linktext with a image if you want a button.

Most browsers will open the pdf document directly if they just leftclick the link. To avoid that, a common thing is to just zip the pdf first.

peteyb
08-16-2006, 08:15 AM
there must be a way to make a left mouse click on the link, image or button trigger the 'save as' or 'save target as' command?

Coulix
08-16-2006, 09:51 AM
Javascript, but considered unsafe and blocked many places to run such a command. Would do more damage than good.

peteyb
08-16-2006, 10:12 AM
okay, if anyone has any ideas it would be much appreciated

the tree
08-16-2006, 10:41 AM
If you know how to, and can, set MIME types then send the .PDF file with "application/octet-stream".

peteyb
08-17-2006, 03:35 AM
not sure how to, are there any guides/tutorials?

felgall
08-17-2006, 04:45 AM
If your visitors want to download the PDF instead of viewing it in their browser then they will either not have the PDF plugin installed so that left clicking will download it or they will right click if they want to download it before seeing what is in it or they will prefer to view it before downloading (a properly constructed PDF can serve one page at a time so that if they decide after seeing the first page that they don't want it then they don't have to download the rest).

pcthug
08-17-2006, 04:54 AM
If you have PHP available to you, use the following script:

<?php

$pdf_file = 'location/of/file.pdf';

if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($pdf_file) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($pdf_file));
readfile($pdf_file);

exit;

?>

the tree
08-17-2006, 07:34 AM
If you have PHP available to you, use the following script:Even better, if you have permission to use .htaccess, then just this:<Files thefile.pdf>
ForceType application/octet-stream
</Files>

peteyb
08-17-2006, 10:40 AM
pcthug, this opens the save or open option but when either is pressed the new screen is not loaded.

the tree, where does this code need to go. at the moment its just printing the message ForceType application/octet-stream on the screen

peteyb
08-17-2006, 10:44 AM
to pcthug, also the file saved and downloaded does not open, error message relating to decoding incorrectly

the tree
08-18-2006, 06:18 AM
A plain text file, named .htaccess *exactly*, not all servers will allow you to use it though.