【发布时间】:2017-11-21 19:46:47
【问题描述】:
我对 FPDI/FPDF 有疑问。我有一个表单,根据选择的选项(1、2 或 3),每个表单使用 1、2 或 3 页的源模板。
$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
}
所以如果 $num_experiencias 是 1,我会在 pdf 中写一些东西,如果数字是 2 或 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);
}
问题是,如果我只想要 1 页($num_experiencias == 1),则输出 pdf 的长度为 6 页(而不是 1 页)。如果 $num_experiencias 为 2,则 pdf 现在为 12 页(应为 2),如果 $num_experiencias 为 3,则 pdf 现在为 18 页(应为 3)。这是怎么回事?哎哟
【问题讨论】:
-
您的脚本最多创建 3 个页面(每个 AddPage() 创建一个页面)。 FPDI 的方法从不创建页面——这取决于您。所以我猜这不是完整的代码。
-
不,不是...我要更新 OP 以包含所有代码。
-
请分享一个示例 PDF 输出。您是否触发了任何自动换页中断?
-
我编辑了我的 OP 并在帖子底部添加了一个屏幕截图。如果 $num_experiencias 为 1,这是输出 pdf ......它应该是 6 页长,而它应该只是一个。 :S 我不知道我是否以某种方式触发了自动页面。