http://www.perlmonks.org?node_id=1064991

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

Hi

I am using Strawberry perl on a Win7 box.

Altho' I have the PDF module installed without error (and PDF::Parse), I can't get the following to run

#!/perl/bin/perl -w use strict; use PDF; my $file = shift; my $pdf=PDF->new($file); my $bool = $pdf->IscryptPDF; my $result = "NO :-(\n"; if ($bool) { $result = "yes!\n"; } print $result;

The docm. for these modules is not overly clear about what is required... at least, it isn't clear to me. So I don't know if I am doing something wrong. "Probably" is usually the right answer!

All I am trying to do is write a small test proggy that'll check if a given PDF is password protected or not.

Any suggestions/help/advice gratefully received.

Thanks

Bill

Replies are listed 'Best First'.
Re: use PDF; woes
by Khen1950fx (Canon) on Nov 29, 2013 at 23:17 UTC
    I ran it like this:
    #!/usr/bin/perl -l use strict; use warnings; use PDF; my $file = '/root/abitl.pdf'; my $pdf = PDF->new; $pdf->TargetFile($file); $pdf->LoadPageInfo; if ( $pdf->IscryptPDF ) { print "File is password-protected"; } else { print "File is not password-protected"; }
    Note: You did use the IscryptPDF method correctly. The documentation for PDF incorrectly lists it as IscryptedPDF.
Re: use PDF; woes
by ww (Archbishop) on Nov 30, 2013 at 00:19 UTC
    Kehn1950fx appears to have hit this one on the head... for some Portable Document Files.......

    However, as has been said about .pdf conversion/testing/whatever -- in many threads here in the Monastery and elsewhere -- the standard for such docs has changed many times; many creators ignore or bork their implementation of the standards; and what you get may not match the output using a different source.

    You may wish to check CAM::PDF and especially http://search.cpan.org/~cdolan/CAM-PDF-1.60/bin/getpdftext.pl if your desire to go further -- for example, to text extraction... but as the author, Chris Dolan http://search.cpan.org/~cdolan/ has noted (in paraphrase) extracting information from some .pdf formats is a real pain.

Re: use PDF; woes
by monkey_boy (Priest) on Nov 29, 2013 at 18:19 UTC

    PDF seems old, unmaintained and broken, try PDF::API2



    This is not a Signature...