Q:

How to detect image orientation (text)

My program is working with fax documents stored as separate bitmaps
I wonder if there is a way to detect automatically page orientation (vertical or horizontal) to show image preview for user in right order (meant rotate if neccesary)
Any advices much appreciated! 
EDIT: Clarification:
When Faxmachine receives multi-page document it saves each page as separate TIFF file. 
My app has built-in viewer displaying those files.   All files are scaled to A4 format and saved in TIFF (so there is no change to detect orientation by height/width parameters)
My viewer displays images in portrait mode by default 
What I'd like to do is automagically detect situation when org document was printed in landscape mode (eg wide Excel tables) then I'd like to show rotated preview for end user to speed up preview process
Obviously there are 4 possible fax orientation  portrait / landscape x 2 kinds of rotations. 
I'm even interested simplified solution detecting when org doc was landscape or portrait (I've noticed most of landscape docs needs to be rotated clockwise)
EDIT2: Idea
I think it might be some idea:
If I could draw horizontal and vertical lines and check if line doesn't cut any (black) point.  Then we can compare what are more type of lines (horizontal or vertical) and his decides about page orientation. 
What do you think ? 

A:

You could perform a Fast Fourier Transform (FFT) to convert your spatial image to a frequency/angle representation.   Then find the angle with the most prominent frequency.   It sounds complicated but it's not that hard, it's pretty efficient, and in effect it tests every possible angle at once, instead of being a hard-coded hack that only works for specific angles.   Search for a sample implementation with search terms like Numerical Recipes and FFT. 

A:

You'd need OCR for that.  Rolling your own OCR would be a bit difficult, but there might be library or something out there worth looking into?   Also, even with good OCR, it's not a 100% reliable solution.