In a Ruby web application I want users to be able to upload documents. If the user uploads a Microsoft Word file (.doc) I want Ruby to count the number of pages in the file. It would be even slicker to get the number of words, but the number of pages will do.
How would I do that? Is there a Ruby library/gem that can do that for me? Is it even possible, given the DOC-format?
In ruby, to open a word file you need to use:
(source: http://www.ruby-forum.com/topic/99742#214485)
See: http://www.perlmonks.org/?node_id=614609 for an algorithm on getting the proper/expected word count (note: the algo is in perl)
Then:
Call the ComputeStatistics() method on the document's Range object:
You'll find various articles on automating Word with Ruby here.