从第一页打印pdf页码并设置页脚

时间:2014-03-10 13:30:44

标签: php fpdf fpdi

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

      $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');

1 个答案:

答案 0 :(得分:0)

您的页脚文字可能会由于其高度而包裹或展开到下一页。尝试通过将偏移量增加到-30:

来移动此文本
$pdf->SetY(-30);

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

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

相关问题