Before you copy-paste a Super Search response, hear me out.
This question has been asked many times : how do you extract text from a PDF document? The answer is always "use CAM::PDF". And believe me, I've tried.
I have never yet seen it produce anything usable. Instead, it produces a string of meaningless characters. I've tried using the included utility getpdftext.pl on various PDFs, including a very simple one created from Open Office, and the result is always meaningless jumble.
Take this PDF for example. It is PDF version 1.3, not encrypted and not optimized. getpdftext.pl produces this:
7A P6. A.X+"NP>. +CRAPZ +CRMP + Q _ JU A ^0 A. GG e + [ m + /? ++Z @7>
+>.M 6C@.N >7@7P.- + Q _ JU _ Z /
_ Z" .-.A KMCK.MP7.N >7@7P.- - +8+Z" _ Z / K # ^ w ++"JZ? & JZ / G+ _m
+ ^ > +U _ // + #? JQQ m +G + _ # " _ // G+ A + ? w_ &/ Q+ 8 m^Z P A Z
++ + ^ 8 Z /A + ^ 8#/ _ / P G+ >_ ? + ^ 8#/& ~L 8 _ A& J"+ ~A + ? w_ &
+/ Q+ 8 m^Z P A Z+ ^Z } : -_ / + } = / G" _ A ^8 " m # JQ 6GG 0 P JU+
+} e G r 1G _ U " Z A m+ #& ^Z G _ > JZ? _ ZJ Z / + # + &/ JZ / G+ & +
+m # ^ w ++"JZ? & _ Z" JZ / +Z"JZ? / ^ _ mm+ _ #& G^ 8 Q" "^ & ^^ Z /
+G+ _m ^ > + " _ / +r
P G+ + Q _ JU _ Z / && ^QJ w J / ^ #& _ # + X_ # " 6_ " _ ? _ A ^8 N
+_ Z"? _ / + 6 ^ 8& + ~ e G6 L 8 _ A& J"+ ~A + ? w_ &/ Q+ 8 m^Z P A Z+
+ ~A . e 1 -Y~ / +Q } G e[e 6G == GGG ~ # +8 } .4 r << r @7> e0er 6* :
+e
pdftotext -layout from xpdf produces this:
IN THE NEWCASTLE COUNTY COURT
Claim No 8NE00169
between
MILLER HOMES LIMITED
Claimant
and
EDEN PROPERTIES LIMITED
Defendant
Proceedings in the above matter will be heard at the
ewcastle upon Tyne County Court at The Law
ourts, Quayside, Newcastle upon Tyne on:−
Date: 4th day of April 2008
Time: 10.30am
ny person having an interest in these proceedings
nd intending to appear should do so on the above
ate.
he Claimant’s solicitors are Ward Hadaway of
andgate House, 102 Quayside, Newcastle upon
yne, NE1 3DX, tel: 0191 204 4000, ref:
F.JJ.MIL181.2751
... clearly dropping the first character on several lines. (It does this in -raw mode as well). And yet xpdf and evince both display this PDF correctly.
So where to from here? I need something that works on linux, preferably OOS, preferably Perl. The other PDF modules on CPAN (such as PDF::API2, PDF::Reuse and PDFLib seem to be intended for generating new PDFs, not extracting the contained text).
So what else can I try? Any suggestions?
Clint
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.