UBE*_*BEX 3 php pdf pdf-generation tcpdf
我的 PHP 程序使用 生成 PDF TCPDF,然后:
对于第 3 步,我想检查上传的文件是否经过数字签名。
更好的是检查上传的文件是否与程序在步骤 1 中生成的文件相同。
Try this:
<?php
//from: http://stackoverflow.com/a/9059073/284932
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;
}
Run Code Online (Sandbox Code Playgroud)
Search "adbe.pkcs7.detached":
//Signed?
echo isStringInFile('mypdf.pdf', 'adbe.pkcs7.detached');
Run Code Online (Sandbox Code Playgroud)
To check if is the same pdf you can use the TCPDF's setKeyWords() to put some unique keys and check with the Smalot PDF Parser:
<?php
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('signed_pdf.pdf'); //com keywords
$details = $pdf->getDetails();
Run Code Online (Sandbox Code Playgroud)