首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用php中的fpdf库设置PDF表格中的页眉和页脚

如何使用php中的fpdf库设置PDF表格中的页眉和页脚
EN

Stack Overflow用户
提问于 2016-02-06 12:03:27
回答 1查看 1.3K关注 0票数 0

我已经使用fpdf库创建了这个表。现在我想在table.so中设置页眉和页脚,查看屏幕截图了解更多详细信息。我想显示公司的名称和接收者的名称,并在页眉中显示更多详细信息。

代码语言:javascript
复制
// 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');
    }
EN

回答 1

Stack Overflow用户

发布于 2016-02-06 12:15:22

你必须创建一个扩展到FPDF类的新类。请参考以下链接解决方案在那里

new class extend to FPDF

FPDF docs add header and footer

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35237192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档