Hi Monks. I am using WWW::Mechanize::Firefox to sequentially get documents from a list of URLs. Within each document I search for a specific string. If found, I skip to the next URL. If not found I print document and then get the next URL in the list. I use the

$t = $mech->text;

method to extract the document text to search. Here's the problem: some of the documents are PDFs. As of release 19 Firefox has a built-in PDF viewer. Although Mechanize says ->text only works for HTML, when I use the

print $mech->content_type;

method it returns the value "text/HTML" for the PDF document. I was surprised that $mech->text returned anything but it did. However, the $mech->text method returned only the first two pages of the PDF and my search string could be anywhere in the document.

Is there some other way to get the content of a PDF? Can I pass the $mech object to another PDF module (most want to read the PDF from a file)? Can I tweak the text method (I really do not have the skill to do this anyway)? Should I save the PDF to a file first and use, say, CAM::PDF to read the PDF page by page?

I appreciate any/all help. Thanks for taking the time to read this.


In reply to Mechanize Firefox text Method by halweitz

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.