Rectangle 27 0

Using fpdf to modify existing pdf in php?


You can use Dhek graphical tool to design a template in JSON format, defining areas (bounds, name, ...) you want to add later on existing PDF (using FPDF and dynamic data). See doc at https://github.com/cchantep/dhek/blob/master/README.md#php-integration .

Note
Rectangle 27 0

Using fpdf to modify existing pdf in php?


// Get total of the pages
$pages_count = $pdf->setSourceFile('your_file.pdf'); 

for($i = 1; $i <= $pages_count; $i++)
{
    $pdf->AddPage(); 

    $tplIdx = $pdf->importPage($i);

    $pdf->useTemplate($tplIdx, 0, 0); 


    $pdf->SetFont('Arial'); 
    $pdf->SetTextColor(255,0,0); 
    $pdf->SetXY(25, 25); 
    $pdf->Write(0, "This is just a simple text"); 
}

Since you want all the pages with the text, one way to do it is putting the code in a loop.

Note
Rectangle 27 0

Using fpdf to modify existing pdf in php?


$outPdf->useTemplate($outPdf->importPage($i), null, null, 0, 0, true);
$pdf->setSourceFile($filename); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
//use the imported page and place it at point 0,0; calculate width and height
//automaticallay and ajust the page size to the size of the imported page 
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
require_once('fpdf.php');
require_once('fpdi.php');

$pdf =& new FPDI();
$pdf->AddPage();

Let me know if you have any errors

Use this page as template, then

Note
Rectangle 27 0

Using fpdf to modify existing pdf in php?


// Get total of the pages
$pages_count = $pdf->setSourceFile('your_file.pdf'); 

for($i = 1; $i <= $pages_count; $i++)
{
    $pdf->AddPage(); 

    $tplIdx = $pdf->importPage($i);

    $pdf->useTemplate($tplIdx, 0, 0); 


    $pdf->SetFont('Arial'); 
    $pdf->SetTextColor(255,0,0); 
    $pdf->SetXY(25, 25); 
    $pdf->Write(0, "This is just a simple text"); 
}

Since you want all the pages with the text, one way to do it is putting the code in a loop.

Note