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

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

Rather late on the reply, but I was just doing something similar. I needed to generate an alphabetical index of publications (all PDF) and wanted it in a nice HTML table with other pertinant metadata (pages, creation date, etc.).

What follows is just a bit of cleaned up PDF reading code:

opendir DIR, '.'; my @pdf = sort { $a->{Title} cmp $b->{Title} } map { scalar( get_info($_) ) } grep { /\.pdf/i && -f $_ } readdir DIR; sub get_info { # Get basic PDF metadata. my $file = shift; my %info; my $pdf = PDF->new($file); return undef unless $pdf->IsaPDF; $info{Filename} = $file; $info{Size} = -s $file; $info{Pages} = $pdf->Pages; for (qw(Title CreationDate ModDate)) { $info{$_} = $pdf->GetInfo($_) } return( wantarray ? %info : \%info ); }

That opens the current directory and results in an alphabetically sorted (if you wanted it sorted by different criteria just change the sort {} section) array of PDF metadata info hashes. $pdf->[0]{Title} is the title of the first PDF in the array.

print "$_->{Title}\n" for @pdf;

Will give you a plain text list of all the document titles. If you only want titles just delete all the hash stuff in the sub and return the title scalar only.


In reply to Re: PDF GetInfo( by Arguile
in thread PDF GetInfo( by axelrose

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



  • 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.