Perl Script that returns the number of pages in a PDF (used to work)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 2levelsabove
    New Member
    • Mar 2008
    • 8

    Perl Script that returns the number of pages in a PDF (used to work)

    I had this script that used to work in order to return the number of pages but it does not seem to work anymore.
    Code:
    #!/usr/local/bin/perl -w
    
    use CAM::PDF;
    
    if (defined($ARGV[0]) && -r $ARGV[0] && $ARGV[0] =~ /\.pdf/i) {
    	my $pdf_file = $ARGV[0];
    	my $doc = CAM::PDF->new($pdf_file, q{}, q{}, 1) || die "ERROR: $CAM::PDF::errstr\n";
    	my $size = length $doc->{content};
    	my $pages = $doc->numPages();
    
    	print "$pages\n";
    } else {
    	print qq{ERROR: Unreadable file '$ARGV[0]' or not a pdf\n};
    }


    Now when I try running it, All I get is the error

    please let me know if you see anything wrong
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    The code will not just stop working something was changed. It is a matter of figuring out changed. Has the module that you are using been updated? Have there been any changes to the server? What errors are you getting, please post the errors.

    --Kevin

    Comment

    • 2levelsabove
      New Member
      • Mar 2008
      • 8

      #3
      Honestly I am just a new programmer on staff. Best of my knowledge nothing was.
      And I am not too good at Perl. I call this module via PHP. Just wanted to see if everything looked OK here.


      We have had some server inconsistencies . I am just trying to go through a process of elimination.

      Oh and thanks for the quick reply

      Comment

      • 2levelsabove
        New Member
        • Mar 2008
        • 8

        #4
        Ok i went to shell and tried running it and got this error:

        //////////////////
        Permission denied

        /////////////

        Comment

        • 2levelsabove
          New Member
          • Mar 2008
          • 8

          #5
          changed permissions on the perl file and now get


          ERROR: Cannot find the index in the PDF content


          Sigh!!!

          Comment

          • eWish
            Recognized Expert Contributor
            • Jul 2007
            • 973

            #6
            I don't see anything in the code that you posted that requires any authentication. So, it does not appear to be an issue with the code posted. Are the PDF files password protected? Are you requiring authentication to the directory where the files are located?

            --Kevin

            Comment

            • 2levelsabove
              New Member
              • Mar 2008
              • 8

              #7
              Ok so this is what i found out. I can run the scripts in shell. But not when it comes to me running it from PHP

              any insights ?

              Comment

              Working...