使用TCPDF创建自定义标头

时间:2019-02-13 04:31:51

标签: php pdf pdf-generation tcpdf

这是tcpdf.php中的标头函数,我在那里进行了更改,但没有扩展它:

public function Header() {
    if ($this->header_xobjid === false) {
        // start a new XObject Template
        $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
        $headerfont = $this->getHeaderFont();
        $headerdata = $this->getHeaderData();
        $this->y = $this->header_margin;
        if ($this->rtl) {
            $this->x = $this->w - $this->original_rMargin;
        } else {
            $this->x = $this->original_lMargin;
        }
        if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
            $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
            if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
                $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
            } elseif ($imgtype == 'svg') {
                $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
            } else {
                false);
                $this->Image(K_PATH_IMAGES.$headerdata['logo'], 'C', 4, $headerdata['logo_width'], '', 'PNG', false, 'C', false, 300, 'C', false, false, 0, false, false, false);
            }
            $imgy = $this->getImageRBY();
        } else {
            $imgy = $this->y;
        }
        $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
        // set starting margin for text data cell
        if ($this->getRTL()) {
            $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
        } else {
            $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
        }
        $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
        $this->SetTextColorArray($this->header_text_color);
        // header title
        $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
        $this->SetX($header_x);
        $this->MultiCell($cw, $cell_height, $headerdata['title'], 0, 'C', 0, 0, '', '', true, 0, false, true, 20, 'M');
        // header string
        $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
        $this->SetX($header_x);
        $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, 'C', 0, 0, '', '', true, 0, false, true, 40, 'M');
        // print an ending header line
        $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
        $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
        if ($this->rtl) {
            $this->SetX($this->original_rMargin);
        } else {
            $this->SetX($this->original_lMargin);
        }
        $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
        $this->endTemplate();
    }
    // print header template
    $x = 0;
    $dx = 0;
    if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
        // adjust margins for booklet mode
        $dx = ($this->original_lMargin - $this->original_rMargin);
    }
    if ($this->rtl) {
        $x = $this->w + $dx;
    } else {
        $x = 0 + $dx;
    }
    $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
    if ($this->header_xobj_autoreset) {
        // reset header xobject template at each page
        $this->header_xobjid = false;
    }
}

Here is how it looks like right now

Here is how it should look like

您会看到标题文本在徽标的前面,应该在徽标的下面。

徽标或文字未居中,我不知道为什么。

如何制作具有特定长度的水平线?

如何为标题提供特定的字体颜色,为所有其他文本提供另一种颜色?

0 个答案:

没有答案