The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::Extract::Word - Extract text from Word files

SYNOPSIS

 # object-based interface
 use Text::Extract::Word;
 my $file = Text::Extract::Word->new("test1.doc");
 my $text = $file->get_text();
 my $body = $file->get_body();
 my $footnotes = $file->get_footnotes();
 my $headers = $file->get_headers();
 my $annotations = $file->get_annotations();
 my $bookmarks = $file->get_bookmarks();
 
 # specify :raw if you don't want the text cleaned
 my $raw = $file->get_text(':raw');

 # legacy interface
 use Text::Extract::Word qw(get_all_text);
 my $text = get_all_text("test1.doc");

DESCRIPTION

This simple module allows the textual contents to be extracted from a Word file. The code was ported from Java code, originally part of the Apache POE project, but extensive code changes were made internally.

OBJECT-BASED INTERFACE

Text::Extract::Word->new($input);

Passed either a file name or an open file handle, this constructor returns an instance that can be used to query the file contents.

METHODS

All the query methods accept an optional filter argument that can take the value ':raw' -- if this is passed the original Word file contents will be returned without any attempt to clean the text.

The default filter attempts to remove Word internal characters used to identify fields (including field instructions), and translate common Unicode 'fancy' quotes into more conventional ISO-8859-1 equivalents, for ease of processing. Table cell markers are also translated into tabs, and paragraph marks into Perl newlines.

get_body([$filter])

Returns the text for the main body of the Word document. This excludes headers, footers, and annotations.

get_headers([$filter])

Returns the header and footer texts for the Word document, as a single scalar string.

get_footnotes([$filter])

Returns the footnote and endnode texts for the Word document, as a single scalar string.

get_annotations([$filter])

Returns the annotation texts for the Word document, as a single scalar string.

get_text([$filter])

Returns the concatenated text from the body, headers, footnotes, and annotations of the the Word document, as a single scalar string.

get_bookmarks([$filter])

Returns the bookmark texts for the Word document, as a hash reference. The keys in the hash are the bookmark names (Word requires that these are unique) and the values are the filtered bookmark texts.

This method can be used to get Word form text data out of a Word file. All text fields in a Word form will normally be labelled as bookmarks, and will be returned by this method. Non-textual form fields (including drop-downs) will not be returned, as these are not labelled as bookmarks.

FUNCTIONS

get_all_text($filename)

The only function exportable by this module, when called on a file name, returns the raw text contents of the Word file. The contents are returned as UTF-8 encoded text. This is unfiltered, for compatibility with previous versions of the module.

TODO

  • handle non-textual form fields

BUGS

  • support for legacy Word - the module does not extract text from Word version 6 or earlier

SEE ALSO

OLE::Storage also has a script lhalw (Let's Have a Look at Word) which extracts text from Word files. This is simply a much smaller module with lighter dependencies, using OLE::Storage_Lite for its storage management.

AUTHOR

Stuart Watt, stuart@morungos.com

COPYRIGHT

Copyright (c) 2010 Stuart Watt. All rights reserved.