0

Salutation, Since a days when i use fpdi for insertion of image in pdf file this response appear : Fatal error: Uncaught Error: Class "setasign\Fpdi\FpdfTpl" not found in C:\wamp\www\QRCode\fpdi\src\Fpdi.php:23 Stack trace: #0 C:\wamp\www\QRCode\CodeQR_2.php(5): include() #1 {main} thrown in C:\wamp\www\QRCode\fpdi\src\Fpdi.php on line 23 i use php version 8.2.0 and fdpi version 2.4.1

i have followed all respones in the forums but not works : i have declared this :

require_once('fpdi/src/Fpdi.php');
require_once('fpdi/src/FpdfTpl.php');
require_once('fpdi/src/autoload.php');

and this: use setasign\Fpdi\Fpdi;

and just this : use \setasign\Fpdi;

i have changed in compser :

"require": {
        "setasign/fpdi-fpdf": "1.6.1"
    }

and this : $pdf = new \setasign\Fpdi\Fpdi();

and finnaly i have added this: require_once('fpdi/src/FpdiTrait.php');

the problem exists and the same response appear : Fatal error: Uncaught Error: Class "setasign\Fpdi\FpdfTpl" not found in C:\wamp\www\QRCode\fpdi\src\Fpdi.php:23 Stack trace: #0 C:\wamp\www\QRCode\CodeQR_2.php(5): include() #1 {main} thrown in C:\wamp\www\QRCode\fpdi\src\Fpdi.php on line 23.

this is the modified code:


<?php
include('FPDF/fpdf.php');
include('fpdi/src/Fpdi.php');
include('fpdi/src/FpdfTpl.php');
include('fpdi/src/autoload.php');

use setasign\Fpdi\Fpdi;

$pdf = new setasign\Fpdi\FPDI();

// get the page count
    $page = $pdf->setSourceFile('C:/wamp/www/QRCode/fichiers_uploades/UN25042019161632012774.pdf');
// iterate through all pages

    // import a page
    $templateId = $pdf->importPage($page);

    $pdf->AddPage();
    // use the imported page and adjust the page size
    $pdf->useTemplate($templateId, ['adjustPageSize' => true]);

    $image = 'QRCodes/CodeQR1.png';

    $pdf->Image($image,110,210);

    $file_name2 = 'C:/wamp/www/QRCode/fichiers_generes/UN25042019161632012774.pdf';

// Output the new PDF
$pdf -> Output($file_name2,'F');
?>

i try to add a text in existing pdf file

1 Answers1

0

I i have found a solution :

  1. install fpi-fpdf from composer :
    composer require setasign/fpdi-fpdf;

2)Insert this code :

    <?php

use setasign\Fpdi\Fpdi;
require_once('vendor/autoload.php');

$file = 'fichiers_uploades/UN250420191895923066.pdf';
$image = 'QRCodes/CodeQR1.png';

$pdf = new Fpdi();
if(file_exists("./".$file)){ 
    $pagecount = $pdf->setSourceFile($file); 
}else{ 
    die('Source PDF not found!'); 
} 
 
// Add watermark image to PDF pages 
for($i=1;$i<=$pagecount;$i++){ 
    $tpl = $pdf->importPage($i); 
    $size = $pdf->getTemplateSize($tpl); 
    $pdf->addPage(); 
    $pdf->useTemplate($tpl, 1, 1, $size['width'], $size['height'], TRUE); 
     
    //Put the watermark 
    $xxx_final = ($size['width']-60); 
    $yyy_final = ($size['height']-65); 
    $pdf->Image($image, $xxx_final, $yyy_final, 0, 0, 'png'); 
} 
 
// Output PDF with watermark 
$pdf->Output('F', 'fichiers_generes/UN250420191895923066.pdf');

thanks.