Reputation: 4136
How can I determine if a PDF file is corrupt (not openable) in PHP? I have downloaded thousands of PDFs via CURL and a small number are incomplete.
Upvotes: 0
Views: 1526
Reputation: 4136
$part = 'pdffile.pdf';
$escPath = str_replace( " ", "\\ ", escapeshellcmd( $part ) );
$out = shell_exec( 'pdfinfo ' . $escPath . ' 2>&1' );
if( $out != null && !preg_match( '~Error~i', $out ) )
echo "GOOD: $part\n";
else
echo "CORRUPT: $part\n";
I can only find a way to do this via the command line. The second line is required to escape file paths.
Upvotes: 1