代码之家  ›  专栏  ›  技术社区  ›  Annton32

FPDI不导入指定数量的页面

  •  0
  • Annton32  · 技术社区  · 7 年前

    我对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_experienceas是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_experienceas==1),则输出pdf的长度为6页(而不是1页)。如果$num_expericias为2,则pdf现在为12页长(当它应为2时);如果$num_expericias为3,则pdf现在为18页长(当它应为3时)。发生什么事?O、 O

    1 回复  |  直到 7 年前
        1
  •  0
  •   Jan Slabon    7 年前

    您的代码似乎会触发自动分页符。

    如果您将字体颜色设置为非白色,您应该可以看到是哪些项目触发了这种情况。

    要禁用它,只需调用

    $pdf->SetAutoPageBreak(false);
    

    在将任何内容写入页面/文档之前。