phpfpdffpdi

Can't make a simple modification of a pdf using Fpdf and Fpdi


I need your need for a problem which I know was asked a few times in different forum, but that I can't solve, probably because I'm a newbie. If I resolve a problem, another one is coming... until I goes back to my first problem etc... I'm just trying to import a pdf using Fpdi and add a text. I tried so many things that I can't remember everything!

This is what I'm doing:

<?php
include_once('includes/FPDF/fpdf.php');
include_once('includes/Fpdi/src/autoload.php');

use setasign\Fpdi\Fpdi;

$pdf= new Fpdi();
$pdf-> AddPage();
$pdf->setSourceFile('includes/TCPDF/doc/report.pdf');
$tplAgence = $pdf->importPage(1);
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(20,20);
$pdf->Write(0,"Come on, write something!");
 
$pdf->Output('hourra.pdf','D');

The beginning of my Fpdi.php looks like this:

<?php
namespace setasign\src;

use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
use setasign\Fpdi\PdfParser\Type\PdfNull;

class Fpdi extends FpdfTpl
{
    use FpdiTrait;
...

I don't know if I have the wrong libraries (if there are any) but the different files for the 2 libraries are:

enter image description here

What I have at the moment is this:

Fatal error: Uncaught Error: Class "setasign\src\FpdfTpl" not found in C:\xampp\htdocs\testProject\includes\Fpdi\src\Fpdi.php:22 Stack trace: #0 C:\xampp\htdocs\testProject\includes\Fpdi\src\autoload.php(18): require_once() #1 C:\xampp\htdocs\testProject\testPDF.php(25): {closure}('setasign\Fpdi\F...') #2 {main} thrown in C:\xampp\htdocs\testProject\includes\Fpdi\src\Fpdi.php on line 22

Please, let me know if you need anything else. Actually, I just need an example I could use as a beginning for my project.

Thanks a lot


Solution

  • It looks like you modified files of FPDI. This:

    <?php
    namespace setasign\src;
    

    ...is wrong. Why did you removed the copyright and license header and modified the namespace?

    Do a fresh install and you're ready to go. You can find the original header for comparsion e.g. here.