PDF's in a Web Page

Associate
Joined
21 Sep 2005
Posts
180
Location
Dundee
I have an application that allows a user to create PDF documents and then stores them on the server, outside of the root. When a user wishes to view the document it is retrieved and embedded into a web page. This works great so long as the user has Acrobat configured to open PDF's in the browser rather than download to their location. However, if they don't they are left with a nasty little red cross in the top left of the browser window. I'd like to remove the inconsistency and am thinking of just making the documents available to download rather than view in the browser.

Has anyone any experience of doing this and have any tips for doing it the best possible way from a user perspective? Will the fact that the files are stored outside of the root have an impact? Will i have to move them somewhere else inside the root temporarily so that they can be downloaded via a link? I'm using PHP. Any help and knowledge gratefully accepted. :)
 
Probably a little browser check would do it. If the browser is a recent IE/FF/Opera open embedded in the browser, otherwise just pass a link to the browser, which will then open/save as it pleases.

Actually, why doesn't just passing the link work? Would open in the browser by default if it could, otherwise would download.
 
How are you 'embedding' the PDF in the page? Are you providing the correct mimetype (application/pdf) so that the browser can attempt to handle it appropriately?

As for downloading files from outside the web root, it'll be no different than displaying on the page. All you should need to do is something such as:

Code:
header("Content-Type: $mimetype");
header("Content-Length: $filesize");
header("Content-Disposition: attachment; filename='$filename_to_save_as'");
readfile($local_filename);

From a user perspective, offer a button for both. Clicking the download button opens up a save-file box, clicking the view button takes me to another page where the PDF displays. All about choice.
 
Last edited:
Thank you for that. I've changed the script to so that the PDF opens in the browser rather than embedded within a web page and that seems to have solved my problems. Carrying the client brand it isn't so great but seems a reasonable compromise. Thanks again. :)
 
Back
Top Bottom