Saturday, January 30, 2010

How to automatically download PDF instead of loading to the browser?

Most of the time accessing a pdf link will lead the browser to load it if the pdf viewer add-on is installed.
But what if we need is to have the pdf to automatically be downloaded once we click the link? One approach that I have tried is to use a javascript that would enforce downloading of the pdf instead of loading it, yet the problem
with javascript is, if it was disabled on the users browser preference making the pdf link broken.
The solution that I have found is via .htaccess.

If your hosting allows you to use .htaccess files, add this directives into the .htaccess at the folder with your PDF-files:

ForceType application/octet-stream
Header set Content-Disposition attachment
Header set Content-Transfer-Encoding binary


This prevents loading the pdf’s into the browser.

N.B.
Make sure the LoadModule headers_module modules/mod_headers.so is loaded on your apache config file
or you will get "Invalid command 'Header'" error

Thursday, January 28, 2010

Margin and Line Height effects on FireFox 3.5.5 on Mac

If you set the margin top and bottom of a <p> tag you have to set the line-height as well as a work around for firefox 3.5.5 on Mac, this work around will not affect other browser both on mac and windows and this is to rectify the line-height spacing of the <p> tag.

Example:
<p style="margin: 11px 0; line-height: 13px">Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum </p>

- this is noticeable if you have multiple paragraph inside a box with a background image, the paragraph appears to be at the center of the box in other browser but not with firefox on mac and you will notice the line-height is not similar to the other browser that renders it.