使用PHP的FPDF与TCPDF为已签名PDF添加批注导致签名丢失的问题求助
使用PHP的FPDF与TCPDF为已签名PDF添加批注导致签名丢失的问题求助
我最近碰到了一个棘手的问题:我想给一份已经完成签名的PDF文件添加一个带批注文本的新页面,原本以为用TCPDF和FPDF能实现这个需求,结果处理后的PDF不仅签名丢失了,连签名验证都通不过——虽然新文件看起来和原文件没什么差别,但实际上签名的有效性已经完全失效了。
我用的代码是这样的:
<?php use Fpdf\Fpdf; use setasign\Fpdi\Fpdi; require_once '../lib/fpdf/Fpdf.php'; require_once '../lib/tcpdf/tcpdf.php'; require_once '../lib/fpdi/src/autoload.php'; // require_once '../vendor/autoload.php'; $pdf = new Fpdi(); $pdf->setSourceFile('test-form-signed.pdf'); // Loop through the pages of the original PDF $pageCount = $pdf->setSourceFile('test-form-signed.pdf'); for ($i = 1; $i <= $pageCount; $i++) { $tplId = $pdf->importPage($i); $pdf->addPage(); $pdf->useTemplate($tplId, 0, 0); } // Add a blank new page at the end $pdf->AddPage(); // Set annotation properties $pdf->SetFont('Helvetica', '', 12); $pdf->SetTextColor(0, 0, 0); $pdf->Text(10, 10, "This is a text annotation on a new blank page."); // Save the output PDF $pdf->Output('F', 'test-form-annotated-signed.pdf');
生成的test-form-annotated-signed.pdf大小只有原文件的一半,而且完全无法通过签名验证,应该是处理过程中签名和证书被移除了。另外补充一下,这份PDF是用丹麦政府颁发的OCES-3证书签署的。
需要说明的是,我不能使用Adobe Acrobat、Signicat这类工具来处理,必须用PHP代码解决这个问题,希望能得到大家的帮助!
备注:内容来源于stack exchange,提问作者Benjamin
相关产品推荐
相关产品推荐

