Gentlemonks,

My lab has a fair number of conference papers and proceedings stashed away as PDFs. I'm trying to write a program to index them and create a web-page interface (which I hope will be more friendly than a ten-level directory tree). The papers' filenames almost invariably contain no more useful information than the primary author's last name, so I'm trying to use PDF::Parse to extract title and author information.

Unfortunately, my script fails with

PDF::Core::PDFGetPrimitive() called too early to check prototype at PD +F/Core.pm line 288. PDF::Core::PDFGetPrimitive() called too early to check prototype at PD +F/Core.pm line 294. Argument "" isn't numeric in seek at PDF/Core.pm line 556. Can't read cross-reference section, according to trailer
and I can't glean enough context from the module's documentation to know when PDF::Core::PDFGetPrimitive() should be called, or why a trailer might not be able to read a cross-reference section.

In fact, I'm finding it very difficult to debug based on the docs for PDF::Parse -- they seem to describe what the module's various functions will do if they succeed, but not what's necessary to ensure success.

My code, mildly edited for length, follows:

#! /usr/bin/perl -w use strict; use File::Find; use Data::Dumper; use PDF; use PDF::Parse; my %conferences = (); my $start_dir = "/gruvi/Data/Proceedings"; sub find_pdfs { # simple, yet shoud be effective if(/\.pdf$/) { # NOTE: this seems to ignore "top-level" PDFs # That's not a bug, it's a feature! my ($conference) = ($File::Find::dir =~ m!$start_dir/(\w+?)/!) +; $conference ||= "Top-level"; push @{$conferences{$conference}}, "$File::Find::dir/$_"; return 1; } return 0; } &File::Find::find(\&find_pdfs, $start_dir); for (sort keys %conferences) { &write_conference_page($_, "$_.html", $conferences{$_}); } sub write_conference_page { my ($conference, $outfile, $pdfs) = @_; open PROCS, '>', "./$outfile" or die "Cannot open $outfile: $!\n"; # we're going to callously ignore proper HTML for the present print PROCS "<html>\n<body>\n"; # we're also going to callously ignore proper Perl HTML-gen style # for the moment print PROCS "<h3>$conference</h3>\n"; print PROCS "<ul>\n"; for (@$pdfs) { my $pdf = PDF->new($_); $pdf->TargetFile($_); my $title = $pdf->GetInfo("Title"); my $authors = $pdf->GetInfo("Author"); print PROCS "\t<li>$authors:<br>"; print PROCS "<a href=\"file://$_\">$title</a></li>\n"; } print PROCS "</ul>\n<hr>\n\n"; print PROCS "</body>\n</html>\n"; close PROCS or die "Cannot close $outfile: $!\n"; }
I'll freely admit that the code around $pdf is cargo-cult stuff -- I couldn't tell from the docs what I was expected to do to make a PDF object, so I just copied from the synopses.

This code fails to generate any of the conference index pages. Any ideas?

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry


In reply to PDF::Parse fails with obscure error messages by FoxtrotUniform

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.