繁体   English   中英

如何使用PHP中的fpdf库在PDF表中设置页眉和页脚

[英]How to set the header and footer in PDF table using the fpdf library in php

我已经使用fpdf库创建了表。 现在我要在table.so中设置页眉和页脚。怎么可能。请看屏幕截图了解更多详细信息。我要显示公司名称和收款人名称,以及页眉中的一些详细信息。 在此处输入图片说明

// Colored table
    private function FancyTable($header, $data) {
        // Colors, line width and bold font
        $this->fpdf->SetFillColor(255, 0, 0);
        $this->fpdf->SetTextColor(255);
        $this->fpdf->SetDrawColor(128, 0, 0);
        $this->fpdf->SetLineWidth(.1);
        $this->fpdf->SetFont('', '', 1);
        // Header
        $w = array(20, 100, 20, 20, 30);
        for ($i = 0; $i < count($header); $i++) {
            $this->fpdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true);
        }
        $this->fpdf->Ln();
        // Color and font restoration
        $this->fpdf->SetFillColor(224, 235, 255);
        $this->fpdf->SetTextColor(0);
        $this->fpdf->SetFont('', '', 10);
        // Data
        $fill = false;
        $this->data_array = array();
        $this->getdata($data, 0);
        foreach ($this->data_array as $row) {
            if (strlen($row[1]) > 50) {
                $this->fpdf->Cell($w[0], 5, $row[0], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[1], 5, substr($row[1], 0, 50), 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[2], 5, $row[2], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[3], 5, $row[3], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[4], 5, $row[4], 'LR', 0, 'L', $fill);
                $this->fpdf->Ln();
                $this->fpdf->Cell($w[0], 5, $row[0] = '', 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[1], 5, substr($row[1], 50), 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[2], 5, $row[2] = '', 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[3], 5, $row[3] = '', 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[4], 5, $row[4] = '', 'LR', 0, 'L', $fill);
                $this->fpdf->Ln();
                $fill = !$fill;
            } else {
                $this->fpdf->Cell($w[0], 5, $row[0], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[1], 5, $row[1], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[2], 5, $row[2], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[3], 5, $row[3], 'LR', 0, 'L', $fill);
                $this->fpdf->Cell($w[4], 5, $row[4], 'LR', 0, 'L', $fill);
                $this->fpdf->Ln();
                $fill = !$fill;
            }
        }
        // Closing line
        $this->fpdf->Cell(array_sum($w), 0, '', 'T');
    }

您必须创建扩展到FPDF类的新类。 请参考以下链接解决方案

新类扩展到FPDF

FPDF文档添加页眉和页脚

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM