#How to Use Perl to Search a PDF Doc
#!/usr/bin/perl
use CAM::PDF;
my $file = shift;
my $search = shift;
my $doc = CAM::PDF->new($file);
foreach my $p ((1 .. $doc->numPages())) {
#print "$p\n";
my $str = $doc->getPageText($p);
@lines = split(/\n/, $str);
}
my $i = 0;
foreach $line (@lines) {
++$i;
if($line =~ /$search/) {
print "\"$search\" found in line $i of page $p\n";
print "$line\n\n"
}
}
No comments:
Post a Comment