简体   繁体   English

确定PDF是否损坏

[英]Determine if a PDF is Corrupt

How can I determine if a PDF file is corrupt (not openable) in PHP? 如何确定PHP中的PDF文件是否已损坏(无法打开)? I have downloaded thousands of PDFs via CURL and a small number are incomplete. 我已经通过CURL下载了成千上万个PDF,其中一小部分是不完整的。

$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. 第二行是转义文件路径所必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM