1

我在下面有这段代码对我来说非常有用,问题是第一页没有编号,然后我设置的页脚显示为页眉,建议

      $full_name = 'custom_worksheets/' . $sheet_name . '.pdf';

        $pdf = new FPDI('P', 'mm', 'A4');
        $pdf->AliasNbPages();
        $pdf->AddPage();
        // set the sourcefile
        $pages_count = $pdf->setSourceFile($full_name);


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

            $tplIdx = $pdf->importPage($i);
    // Go to 1.5 cm from bottom
            $pdf->SetY(-31);
            // Select Arial italic 8
            $pdf->SetFont('Arial', 'I', 8);
            // Print centered page number
            $pdf->Cell(0, 10, 'Page ' . $pdf->PageNo() . ' of {nb}', 0, 0, 'C');
            $pdf->Cell(0, 10, date('d/m/Y'), 0, 0, 'R');
            $pdf->Cell(0, 0,$labref . '/' . ucfirst(str_replace('_', ' ', $sheet_name)) . ' / Download x : author - ' . $full_names,0,0);

            $pdf->useTemplate($tplIdx);




        }


       // Output
        $pdf->Output('generated_custom_sheets/' . $labref . '_' . $sheet_name . '.pdf', 'D');

        redirect('generated_custom_sheets/' . $labref . '_' . $sheet_name . '.pdf');
4

1 回答 1

0

由于在下一页上的高度,您的页脚文本可能会换行或展开。尝试通过将偏移量增加到 -30 来向上移动此文本:

$pdf->SetY(-30);

这可以帮助排除进入下一页的文本。您的 pdf 可能已经换到下一页,因此您可以将此页脚绘制逻辑移到模板上方,以便首先绘制页脚,然后将模板 SetY 放在页面顶部以自行编写。我总是先画我的页脚和页眉,然后是我的 pdf 页面的内容。

我还建议您从 切换Write到 a,Cell因为 Write 是一个自由流动的文本对象。

于 2014-03-10T13:39:40.907 回答