i want to import an existing PDF file using TCPDF and FPDI and add a watermark and a stamp image to my PDF but i have this error
This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details)
i tried using ghostscript but still get the same error,
use setasign\Fpdi\Fpdi;
require_once(__DIR__ . '/../../../../vendor/autoload.php');
use TCPDF;
public function updateMemoirePdf($selectedProject)
{
$file = public_path("uploads/themes/{$selectedProject->theme}/memoire/{$selectedProject->memoire_path}");
$newPdfPath = public_path("uploads/themes/{$selectedProject->theme}/memoire/{$selectedProject->memoire_path}_modified.pdf");
if (file_exists($file)) {
// Créer une instance de TCPDF
shell_exec( "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$newPdfPath." ".$file."");
$pdf = new FPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
$pageCount = $pdf->setSourceFile($file);
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
$pdf->AddPage();
$pdf->setSourceFile($file);
$tplIdx = $pdf->importPage($pageNumber);
$pdf->useTemplate($tplIdx, 0, 0, 210);
$pdf->SetFont('helvetica', '', 10);
$pdf->SetTextColor(192, 192, 192); // Couleur du texte en filigrane (gris clair)
$pdf->SetXY(15, 285); // Position du texte en bas à gauche
$pdf->Write(0, 'Published by Te-Sea Publication');
$stampImage = public_path('assets/img/te-sea1.png');
$pdf->Image($stampImage, 10, 10, 50, 0, 'PNG');
}
$pdf->Output($newPdfPath, 'F');
$selectedProject->memoire_path = "{$selectedProject->memoire_path}_modified.pdf";
$selectedProject->save();
return $newPdfPath;
} else {
throw new \Exception('Source PDF not found!');
}
}
Please can someone help me with the solution?
Note: i tried to use TCPDF only but i had this error call to undefined method elibyy\tcpdf\facades\tcpdf::setsourcefile() so i tried combining it with FPDI library