#!C:\Perl\bin\perl -w
use CAM::PDF;

my $boxLimit = 750; # This is the limit of boxes accepted on a page.
my @files = <*>;
foreach $file (@files) {
 if ($file =~ m/(\.pdf|\.PDF)/) {
  print "$file checking, ";
  my $pdf = CAM::PDF->new($file);

  my $pageCount = $pdf->numPages();
  
  for (my $pageNumber = 1; $pageNumber < $pageCount; $pageNumber++) {
   my $pageContent = $pdf->getPageContent($pageNumber);
   $pageContent =~ s/\n//g;

   my @matches = $pageContent =~ /BT.*?ET/g;
   my $count = @matches;
   if ($count > $boxLimit) {
    print "\n    Possible tearing problem (purple boxes) on page $pageNumber, ";
   }
  }
  print "done.\n";
 }
}