I have a problem with FPDI/FPDF. I have a form that according to the chosen option (1, 2 or 3), either uses the source template for 1, 2 or 3 pages each.
$num_experiencias = $_POST["totalExpPdf"];
if($num_experiencias == "1"){
$pdf->setSourceFile(dirname(dirname(__FILE__)) .'/pdfs/guia_uno_blanco.pdf'); // one blank page
} else if($num_experiencias == "2"){
$pdf->setSourceFile(dirname(dirname(__FILE__)) .'/pdfs/guia_dos_blanco.pdf'); // two blank pages
} else{
$pdf->setSourceFile(dirname(dirname(__FILE__)) .'/pdfs/guia_tres_blanco.pdf'); // three blank pages
}
So if $num_experiencias is 1, I write something in the pdf and likewise I write other stuff if the number is 2 or 3.
// ******** PAGE 1 ********
$pageId = $pdf->ImportPage(1);
$pdf->AddPage();
$pdf->useTemplate($pageId, null, null, 0, 0, true);
// IMAGE
$pdf->Image($imagen1,10,10,234,170);
// NUM EXP
$pdf->SetXY(30, 35);
$pdf->SetFont('Quicksand-Regular', '', 16);
$pdf->SetTextColor(255, 255, 255);
$pdf->MultiCell(50, 13, utf8_decode('Experiencia 1/'.$num_experiencias), 0, 'C');
// ******** PAGE 2 ********
if ($num_experiencias >= "2"){
$pageId = $pdf->ImportPage(2);
$pdf->AddPage();
$pdf->useTemplate($pageId, null, null, 0, 0, true);
// IMAGE
$pdf->Image($imagen2,10,10,234,170);
}
// ******** PAGE 3 ********
if($num_experiencias == "3"){
$pageId = $pdf->ImportPage(3);
$pdf->AddPage();
$pdf->useTemplate($pageId, null, null, 0, 0, true);
// IMAGE
$pdf->Image($imagen3,10,10,234,170);
}
The problem is that if I want only 1 page ($num_experiencias == 1), the output pdf is 6 pages long (instead of 1). If $num_experiencias is 2, the pdf is now 12 pages long (when it should be 2) and if $num_experiencias is 3, the pdf is now 18 pages long (when it should be 3). What's going on? O.o