Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Mechanize Firefox text Method

by halweitz (Novice)
on May 05, 2013 at 00:45 UTC ( #1032095=note: print w/ replies, xml ) Need Help??


in reply to Re: Mechanize Firefox text Method
in thread Mechanize Firefox text Method

Thanks for the reply. Actually, I want the post release 19 behavior because this allows the ->text method to return the text of the PDF but it does not return all the text. Therein lies my problem. I tried to set the viewer to Adobe Reader but in that case I lose script control of the document.


Comment on Re^2: Mechanize Firefox text Method
Re^3: Mechanize Firefox text Method
by afoken (Parson) on May 05, 2013 at 05:20 UTC

    PDF does not always contain text. I've seen lots of PDF files that were composed of images (scanned texts, no OCR involved). So getting no text or much less text than expected is not always a problem in your code.

    PDF is a "postscript print job on steroides". PDF is basically postscript, with lots of addons that aren't really relevant for your problem. Postscript describes how to print a page. Most times, it works roughly in reading order, but neither postscript nor PDF have a problem with a print job that first emits all "A"s, then all "B"s, then all "C"s, and so on. It inflates the print job, and it makes it really hard to extract the original text, and there seems to be software written for exactly this purpose.

    I think a much cleaner way is to determinate the URL of the PDF file (using Mechanize), download the PDF file (using LWP or Mechanize), and process the PDF file using tools like pdftotext.

    Note that you still need some OCR software for scanned images, pdftotext just extracts text from the PDF file.

    Update: There are several commercial OCR programs that can take PDF files (including those composed of scanned images) as input and deliver text or Word documents.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Thanks again for your reply. Let me clarify a bit. Since I can read the documents in the browser I know they contain only text so OCR is not an issue. All the documents follow a similar set of templates but the content changes for each. I have viewed hundreds of these and any document that does not conform will be skipped.

      Your comments on downloading and then using a pdftotext tool on the local file is inline with my current thinking as long as it can be scripted and run without intervention. Are there any other suggestions I should examine?

        Let me clarify a bit. Since I can read the documents in the browser I know they contain only text so OCR is not an issue.

        I think we have a little communication problem: Sure you can read text displayed in Firefox, because it was rendered from something like <html><body><h1>Hello</h1>. But you can also read text displayed in Firefox that was rendered from something like <html><body><img src="http://www.example.com/pics/hello.gif" alt="">. Your computer can't, at least not as easy as you. To extract the text from the latter, you need OCR.

        All the documents follow a similar set of templates but the content changes for each.

        Any chance to get access to the data before the template engine creates the PDF? Perhaps as XML, JSON, CSV or even HTML?

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      have a look at CAM::PDF. I have used to do text searchs in PDFs with hundreds of pages.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-08-23 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls