kiz has asked for the wisdom of the Perl Monks concerning the following question:

I'm wanting to get details from a pdf file. I can get the easy stuff:
*File: Bathgate_ASRs.pdf Author ->Bob Webster CreationDate ->D:20060817180621+01'00' Creator ->Writer Producer ->OpenOffice.org 2.0 Title ->COMPETITIVE SAFARI MD5 Checksum: 18221baccb3c49a73dc9772302897e50 Size: ~169 KB (173585)
using the following snippit of code:
sub check_file { my $file = shift; my $pdf = PDF::API2->open($file); my %info = $pdf->info; print "\n*File: $filename\n"; foreach my $key (sort keys %info) { print "$key ->"; print narrow_char($info{$key}); print "\n"; } open (FILE, $file); binmode(FILE); print "MD5 Checksum: ",Digest::MD5->new->addfile(*FILE)->hexdigest, +"\n"; close(FILE); my $size = (stat("$file"))[7]; my $orig_size = $size; if ($size < 1024) { print "Size: $size bytes\n"; $size = undef; } if ($size) { $size = int($size / 1024); if ($size && $size < 1024) { print "Size: ~$size KB ($orig_size)\n"; $size = undef; } } if ($size) { $size = int($size / 1024); print "Size: ~$size MB ($orig_size)\n"; } }

What I now want find out two more things: the version of the pdf format, and the number of pages in the document... anyone got any hints?



-- Ian Stuart
A man depriving some poor village, somewhere, of a first-class idiot.

Replies are listed 'Best First'.
Re: Getting details from pdf files..
by prasadbabu (Prior) on Oct 05, 2006 at 10:15 UTC

    To get the total number of pages, you can use CAM::PDF. PDF can also be used for finding version and pages, $pdf->Version, $pdf->Pages.

    use CAM::PDF; my $filename = $ARGV[0]; #get the filename from the user my $pdf=PDF->new("$filename"); my $self = CAM::PDF->new("$filename"); #total no of pages my $pages = $self->numPages(); print "\n\nTotal number of pages: $pages\n\n"; untested:

    Prasad

Re: Getting details from pdf files..
by Samy_rio (Vicar) on Oct 05, 2006 at 10:17 UTC

    Hi kiz, Try like this,

    use strict; use warnings; use PDF; my $pdf=PDF->new("C:\\gluix.pdf"); print "Is a pdf file\n" if ( $pdf->IsaPDF ) ; print "Has \"",$pdf->Pages,"\" Pages \n"; print "Use a PDF Version \"",$pdf->Version ,"\" \n";

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Re: Getting details from pdf files..
by stvn (Monsignor) on Oct 05, 2006 at 12:06 UTC

    I am going to agree with prasadbabu above, that CAM::PDF is a really great module for stuff like this. So much so that I was able to write Test::PDF with it. I also found the author very responsive and willing the help answer my questions. Good stuff.

    -stvn
Re: Getting details from pdf files..
by marto (Cardinal) on Oct 05, 2006 at 17:58 UTC
    kiz,

    Did you use Super Search before posting? This question gets asked and answered every so often.

    Martin