I’m trying to add a page with an annotation box to an existing signed pdf. This should be possible with TCPDF and FPDF. Unfortunately, it removes the sign and the pdf cannot be validated after being altered. The displayed pdf looks the same, though.
The code (generated by AI) follows:
<?php
use FpdfFpdf;
use setasignFpdiFpdi;
require_once '../lib/fpdf/Fpdf.php';
require_once '../lib/tcpdf/tcpdf.php';
require_once '../lib/fpdi/src/autoload.php';
// require_once '../vendor/autoload.php';
$fpdf = new FPDFFPDF();
$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');
The test-form-annotated-signed.pdf is about half the size of the original file and it no longer passes a validation test. Probably, the signature/certificate was removed during the process.
By the way, the pdf is signed with a OCES-3 certificate issued by the State of Denmark.
Please note that solutions that involve using Adobe Acrobat, Signicat etc. are not an option.