tags:

views:

255

answers:

3

Pretty simply, I need to rip text out of multiple PDFs (quite a lot actually) in order to analyse the contents before sticking it in an SQL database.

I've found some pretty sketchy free C# libraries that sort of work (the best one uses iTextSharp), but there are umpteen formatting errors and some characters are scrambled and alot of the time there are spaces (' ') EVERYWHERE - inside words, between every letter, huge blocks of them taking up several lines, it all seems a bit random.

Is there any easy way of doing this that I'm completely overlooking (quite likely!) or is it a bit of an arduous task that involves converting the extracted byte values into letters reliably?

Cheers,

Duncan

+4  A: 

You may take a look at this article. It's based on the excellent iTextSharp library.

Darin Dimitrov
Yeah this is the one I was using, it was pretty good although not amazingly reliable.However, looking at Tarydon's answer below explains why, and in actual fact it's probably the best I'm going to find!Cheers
Duncan Tait
+2  A: 

There may be some difficulty in doing this reliably. The problem is that PDF is a presentation format which attaches importance to good typography. Suppose you just wanted to output a single word: Tap.

A PDF rendering engine might output this as 2 separate calls, as shown in this pseudo-code:

moveto (x1, y); output ("T")
moveto (x2, y); output ("ap")

This would be done because the default kerning (inter-letter spacing) between the letters T and a might not be acceptable to the rendering engine, or it might be adding or removing some micro space between characters to get a fully justified line. What this finally results in is that the actual text fragments found in PDF are very often not full words, but pieces of them.

Tarydon
A: 

You can use "CZ-Pdf2Txt COM", it can extract text from pdf files, and it can convert pdf files to delimit table text, or csv files.

This tool can preserve original document layout, and supports command line and COM interface, so you can call it from your application, you can get demo version and more information from http://www.convertzone.com/pdf2txtcom/help.htm

regards
flyaga

flyaga