开发者

How can I extract text from specific binary file formats?

In .Net, what would be the best way to extract all the text out of several binary file formats: PDF, Word, Excel, and PowerPoint.

It doesn't need to be formatted, just a big dump of the text in the file.

Code would be great, but I really just need to get 开发者_开发知识库pointed to some best practices or patterns on it.


I'm surprised no one has mentioned IFilters. IFilters is what Microsoft uses to index documents in windows. You'll have to do some googling to find IFilters for the specific formats you're looking for, but you should find most of what you need. A word of caution though, IFilters aren't perfect. They have issues.....

Here's a CodProject article to get you started: http://www.codeproject.com/KB/cs/IFilter.aspx


Well, the same as in any other language/environment: Understand the file format enough to extract strings.

And yes, for many file formats this means that you should write at least half a parser for the format. PDF is especially icky, as there are no spaces per se; that's just a convention of how far apart the glyphs are; furthermore PDF can contain compressed streams so simply searching for printable strings in the file doesn't yield anything of value.

Naturally, you can look for a library or another tool which already does this. I've seen a document repository which simply passed PDF files through pdf2ascii and fed the resulting text to Lucene.


You'd probably have to implement a different way to handle each file type. There is a lot of sample code around to read these formats, using office interop etc.. then you could write a method that looked at the first few bytes to work out what format the document is, or the extension and send it to the specific reader for that type of document.


Check out Apache Tika.

It supports:

  1. Microsoft Excel
  2. Microsoft Word
  3. Microsoft PowerPoint
  4. Microsoft Visio
  5. Microsoft Outlook
  6. Portable Document Format (PDF)
  7. OpenDocument
  8. Plain text
  9. Rich Text Format
  10. gzip compression
  11. bzip2 compression
  12. MP3 Audio
  13. MIDI audio
  14. Wave audio
  15. XML
  16. HTML
  17. Java class files
  18. Java jar archives
  19. tar archive
  20. ZIP archive


Look into Office Interop using .Net for the Office ones. For PDF, see here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜