1
votes

I am trying to import a pdf document with FPDI and add some text to it but when I try to open the new pdf get the error message "format error: not a PDF or corrupted"!

Here is the code:

require_once ('fpdf.php'); require_once ('fpdi.php');

// initiate FPDI 
$pdf = new FPDI();
// add a page kl
$pdf->AddPage(); 
// set the sourcefile 
$pdf->setSourceFile('doc1.pdf'); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
// use the imported page  
$pdf->useTemplate($tplIdx); 

// now write some text above the imported page 
$pdf->SetFont('Arial'); 
$pdf->SetTextColor(255,0,0); 
$pdf->SetXY(25, 25); 
$pdf->Write(0, "This is just a simple text"); 

$pdf->Output('newpdf.pdf', 'D'); 

I downloaded this code from the FPDI website and customized this. The PDF version of my file is 1.3 . (The documentation says FPDI can work with PDFs up to version 1.5) Tried older versions of FPDI and fpdf_tpl.php but still get this error. I couldn't find the answer neither with GOOGLE nor in this forum!

Any help appreciated!

UPDATE

In the meantime I found the problem!

All the files were up to date except FPDF! I used an old version of FPDF. Now I use 1.7 instead of 1.5.

1
does it work with out the write?Ibu
In the meantime I found the problem!Zolka
All the files were up to date except FPDF! I used an old version of FPDF. Now I use 1.7 instead of 1.5.Zolka
maybe you can post it here so if someone else run into the same problemIbu

1 Answers

0
votes

from the website, FPDF has to be version 1.6 or below to work with FPDI