#!PERL.EXE -w
use strict;
use PDF::API2;

print "Please enter the PDF file name to check ";
my $fname=<STDIN>;
chomp($fname);

my ($error, $pages)=pdf_check_intial($fname);

if (defined($error) and ($error ne ""))
{
    print "Problem: $error\n";
} else {
    print "Page count: $pages\n";
}



###############################################################################
sub pdf_check_intial
{
    my ($file) = @_;
    (-f $file and -r $file) or return("the file is missing",undef);
    my $pdf = PDF::API2->open($file);
    my $encr = $pdf->isEncrypted;
    my $npag = $pdf->pages;
    $pdf->end;
    $encr and return("the file is encrypted",undef);
    $npag or  return("the file is incompabile with PDF::API2 (undetermined number of pages)",undef);
    return(undef, $npag);
}