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:&#8722; 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


In reply to Extracting text from PDF. No really by clinton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.