我的PHP程序使用TCPDF生成PDF文件,然后:
更好的方法是检查上传的文件是否与第1步生成的文件相同。
- 用户下载PDF文件;
- 用户对PDF文件进行数字签名;
- 用户上传已签名的PDF文件;
更好的方法是检查上传的文件是否与第1步生成的文件相同。
试试这个:
<?php
//from: https://dev59.com/XGox5IYBdhLWcg3wql9t#9059073
function isStringInFile($file,$string){
$handle = fopen($file, 'r');
$valid = false; // init as false
while (($buffer = fgets($handle)) !== false) {
if (strpos($buffer, $string) !== false) {
$valid = TRUE;
break; // Once you find the string, you should break out the loop.
}
}
fclose($handle);
return $valid;
}
搜索"adbe.pkcs7.detached":
//Signed?
echo isStringInFile('mypdf.pdf', 'adbe.pkcs7.detached');
要检查是否为相同的PDF文件,您可以使用TCPDF的setKeyWords()来添加一些唯一的关键词,并使用 Smalot PDF解析器进行检查:
<?php
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('signed_pdf.pdf'); //com keywords
$details = $pdf->getDetails();